FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 10-04-2008, 07:48 PM
Thomas Johansson
 
Default Trouble using date function in centos

Is there someone that can explain why I get incorrect results on centos
4.6 and 4.7 but not on centos 5.2??


The date "2008-10-26 +1 days" should results in 2008-10-27

On centos 4.6
--------------
test000:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
2008-10-26
test000:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
2008-10-26
test000:/% uname -a
Linux test000... 2.6.9-67.ELsmp #1 SMP Fri Nov 16 12:48:03 EST 2007 i686
i686 i386 GNU/Linux


On centos 4.7
--------------
test001:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
2008-10-26
test001:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
2008-10-26
test001:/% uname -a
Linux test001... 2.6.9-78.0.1.ELsmp #1 SMP Tue Aug 5 11:02:47 EDT 2008
i686 athlon i386 GNU/Linux


On centos 5.2
--------------
test002:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
2008-10-27
test002:/% uname -a
Linux test002... 2.6.18-92.1.10.el5 #1 SMP Tue Aug 5 07:42:41 EDT 2008
x86_64 x86_64 x86_64 GNU/Linux

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-04-2008, 08:01 PM
Stephen Harris
 
Default Trouble using date function in centos

On Sat, Oct 04, 2008 at 09:48:28PM +0200, Thomas Johansson wrote:
> Is there someone that can explain why I get incorrect results on centos
> 4.6 and 4.7 but not on centos 5.2??

> test000:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
> 2008-10-26
> test000:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
> 2008-10-26


My initial immediate guess would be daylight savings related; if in
your timezone the clock goes back on the 26th then 2008-10-26 (which
means 00:00) + 24 hours would only be 2008-10-26 23:00.

You can see this if you don't specify the format string

centos4.7$ date -d "2008-11-01 +1 days"
Sun Nov 2 00:00:00 EDT 2008
centos4.7$ date -d "2008-11-02 +1 days"
Sun Nov 2 23:00:00 EST 2008

However, in Centos5.2...

centos5.2$ date -d "2008-11-01 +1 days"
Sun Nov 2 00:00:00 EDT 2008
centos5.2$ date -d "2008-11-02 +1 days"
Mon Nov 3 00:00:00 EST 2008

Why the difference in behaviour, I dunno. But if this _IS_ your problem
then you can specify 4am as the time to add 1 day to.

centos4.7$ date -d "2008-11-01 04:00 +1 days" "+%Y-%m-%d"
2008-11-02
centos4.7$ date -d "2008-11-02 04:00 +1 days" "+%Y-%m-%d"
2008-11-03

That'll work on both :-)

--

rgds
Stephen
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-04-2008, 08:26 PM
"William L. Maltby"
 
Default Trouble using date function in centos

On Sat, 2008-10-04 at 21:48 +0200, Thomas Johansson wrote:
> <snip>

> On centos 4.6
> --------------
> test000:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
> 2008-10-26
> test000:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
> 2008-10-26
> test000:/% uname -a
> Linux test000... 2.6.9-67.ELsmp #1 SMP Fri Nov 16 12:48:03 EST 2007 i686
> i686 i386 GNU/Linux
>
> On centos 4.7
> --------------
> test001:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
> 2008-10-26
> test001:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
> 2008-10-26

I just typed the above in on the console on my 4.7 node. WFM.

> test001:/% uname -a
> Linux test001... 2.6.9-78.0.1.ELsmp #1 SMP Tue Aug 5 11:02:47 EDT 2008
> i686 athlon i386 GNU/Linux

My kernel doesn't have the "smp", but otherwise matches.

> <snip>

Another posted the possibility of TZ issues. Seems unlikely to me since
you are providing a date string that does not require the system time
zone information. It just converts to the binary offset value from the
epoch, adds the binary equivalent of a day in seconds (IIRC) and formats
the results as a string.

Maybe some library (like the ones used by asctime, ctime, ...) which are
section 3 system calls (those used buy programs like date) are out of
sync? Have you tried the rpm --verify to see if any discrepancies are
reported?

HTH
--
Bill

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-04-2008, 08:40 PM
"William L. Maltby"
 
Default Trouble using date function in centos

On Sat, 2008-10-04 at 16:26 -0400, William L. Maltby wrote:
> <snip>

> >
> > On centos 4.7
> > --------------
> > test001:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
> > 2008-10-26
> > test001:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
> > 2008-10-26
>
> I just typed the above in on the console on my 4.7 node. WFM.
>
> > test001:/% uname -a
> > Linux test001... 2.6.9-78.0.1.ELsmp #1 SMP Tue Aug 5 11:02:47 EDT 2008
> > i686 athlon i386 GNU/Linux
>
> My kernel doesn't have the "smp", but otherwise matches.
>
> > <snip>
>
> Another posted the possibility of TZ issues. Seems unlikely to me since
> you are providing a date string that does not require the system time
> zone information. It just converts to the binary offset value from the
> epoch, adds the binary equivalent of a day in seconds (IIRC) and formats
> the results as a string.
>
> Maybe some library (like the ones used by asctime, ctime, ...) which are
> section 3 system calls (those used buy programs like date) are out of
> sync? Have you tried the rpm --verify to see if any discrepancies are
> reported?

BTW, rpm -q --whatprovides /bin/date over here indicates
coreutils-5.2.1-31.8.el4

I've not run the prerequisites for that, but there should be several
specific libraries versions that must be in place. If one or more of
those libraries has been updated from another repositiry or corrupted,
that may be your problem.

Another thought: sometimes folks have a local alias or a similarly named
command in an earlier part of $PATH (e.g. export PATH=$HOME/bin:$PATH)
and then we (they) forget they did that. Or they inherit a system from
another who made a similar modification. "whereis" date should reveal if
that is the case.

--
Bill

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-05-2008, 09:59 AM
Thomas Johansson
 
Default Trouble using date function in centos

Stephen Harris wrote:

On Sat, Oct 04, 2008 at 09:48:28PM +0200, Thomas Johansson wrote:
Is there someone that can explain why I get incorrect results on centos
4.6 and 4.7 but not on centos 5.2??



test000:/% date -d "2008-10-25 +1 days" "+%Y-%m-%d"
2008-10-26
test000:/% date -d "2008-10-26 +1 days" "+%Y-%m-%d"
2008-10-26



My initial immediate guess would be daylight savings related; if in
your timezone the clock goes back on the 26th then 2008-10-26 (which
means 00:00) + 24 hours would only be 2008-10-26 23:00.

That was my problem. Became confused when i got different behavior on
centos 4 and centos 5. Problem solved! Thank you!


To avoid that kind of trouble i moved to perl for the date functionality
in my script. That solution is also more portable across my different
*nix platforms.

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 06:51 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org