LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-06-2009, 05:41 AM   #1
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,609

Rep: Reputation: 131Reputation: 131
date command problems


Hi all,

I'm trying to use "date" to calculate some dates. I'm getting some wrong results and wonder, if I'm doing something wrong here. If someone has any idea or if your "date" works as expected, please post here. In case it works on your machine could you please tell me which version of coreutils you have installed?

The example code I'm using follows. I first create a date, which should switch to a previous day if I substract some minutes.

The code and the results I get:
Code:
bash-3.1$ REC_YEAR=2009
bash-3.1$ REC_MONTH=9
bash-3.1$ REC_DAY=1
bash-3.1$ REC_HOUR=0
bash-3.1$ REC_MIN=3
bash-3.1$ date -d "$REC_YEAR-$REC_MONTH-$REC_DAY $REC_HOUR:$REC_MIN" +"%d.%m.%Y %H.%M"
01.09.2009 00.03
bash-3.1$ date -d "$REC_YEAR-$REC_MONTH-$REC_DAY $REC_HOUR:$REC_MIN -5 minutes" +"%d.%m.%Y %H.%M"
01.09.2009 07.04 # <- coreutils version 7.4
bash-3.1$ date -d "$REC_YEAR-$REC_MONTH-$REC_DAY $REC_HOUR:$REC_MIN -5 minutes" +"%d.%m.%Y %H.%M"
01.09.2009 02.09 # <- coreutils version 6.12
To try it out, just the code:

Code:
REC_YEAR=2009
REC_MONTH=9
REC_DAY=1
REC_HOUR=0
REC_MIN=3
date -d "$REC_YEAR-$REC_MONTH-$REC_DAY $REC_HOUR:$REC_MIN" +"%d.%m.%Y %H.%M"
date -d "$REC_YEAR-$REC_MONTH-$REC_DAY $REC_HOUR:$REC_MIN -5 minutes" +"%d.%m.%Y %H.%M"
Thanks for reading my post and any replies!
 
Old 08-06-2009, 05:55 AM   #2
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,609

Original Poster
Rep: Reputation: 131Reputation: 131
EDIT: Did some further tests, and get it "kind of" working. It doesn't look logical though to me, because besides using UTC time I have to ADD some minutes to actually SUBSTRACT them. Oh boy

Code:
bash-3.1$ date -u -d "$REC_YEAR-$REC_MONTH-$REC_DAY $REC_HOUR:$REC_MIN + 5 minutes" +"%d.%m.%Y %H.%M"
31.08.2009 23.59
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
date command is not accepting monu Linux - General 7 10-25-2007 10:20 AM
Problems with the +%A function for date command xxmustainexx Programming 1 10-20-2006 04:49 PM
command for date DarReNz Solaris / OpenSolaris 7 09-05-2006 10:53 AM
date command aetucker1 Linux - General 3 01-21-2005 01:57 PM
need help with date command syntax bigcletus Linux - Newbie 1 08-02-2003 02:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration