Bug in date command?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Operating Systems Linux Bug in date command?
# 1  
Wrench Bug in date command?

Why is the result of this command off (or less) by one hour

Code:
date --date "1979-10-26 +54 hours" +%Y%m%d%H

The result is
Code:
1979102805

It actually should be
Code:
1979102806

It does it with adding minutes as well and only occurs on Oct. 26, from what I can tell. What's going on here?

Last edited by Scott; 08-06-2013 at 06:34 PM.. Reason: Please use code tags
# 2  
Spring forward, fall back.

When do the clocks change?

Perhaps?
# 3  
Quote:
Originally Posted by Scott
Spring forward, fall back.
Yep. In the UK and North America and a few other places, DST ended within the specified 54 hour interval: Daylight Saving Time Around the World 1979

Regards,
Alister
# 4  
Quite interesting and esoteric.

How would you work around this?

---------- Post updated at 09:40 PM ---------- Previous update was at 09:18 PM ----------

Looking back at the results of the date command now (with the way I'm using it), I'm finding the answers to be off by +1 or -1 hr depending on the month (not just March and October). It may be a bigger problem.
# 5  
Quote:
Originally Posted by hsemune
Quite interesting and esoteric.

How would you work around this?
What is there to work around? There is nothing wrong with the result. The only possible issue is that your date format is ambiguous because it does not include a timezone.

If you prefer to avoid daylight savings time, use UTC.

Regards,
Alister
# 6  
Hi Alister,

Adding daylight savings time or any other time zones does not correct this issue. I still see the hour result being incremented by -1 or 1, whether it's in March, October, July, February, November. I'm still befuddled by this...

Thanks!

---------- Post updated at 09:47 AM ---------- Previous update was at 08:15 AM ----------

I wrote an if statement adding or subtracting an hour when I encounter this, so the problem is solved for me. But it's less than ideal that I have to write additional code to work around an important and widely used script function.
# 7  
I think the question has already been answered, but to reduce confusion, perhaps include the time zone %Z to see what is happening...
Code:
$ date --date "1979-10-26" '+%Y%m%d%H %Z'
1979102600 GMTDT

$ date --date "1979-10-26 +54 hours" '+%Y%m%d%H %Z'
1979102805 GMTST

$ date --utc --date "1979-10-26 +54 hours" '+%Y%m%d%H %Z'
1979102806 UTC

$

If you are still "befuddled", then that is to be expected. The first page of info date provides a quote...
Code:
File: coreutils.info,  Node: Date input formats

28 Date input formats
*********************

First, a quote:

     Our units of temporal measurement, from seconds on up to months,
     are so complicated, asymmetrical and disjunctive so as to make
     coherent mental reckoning in time all but impossible.  Indeed, had
     some tyrannical god contrived to enslave our minds to time, to
     make it all but impossible for us to escape subjection to sodden
     routines and unpleasant surprises, he could hardly have done
     better than handing down our present system.  It is like a set of
     trapezoidal building blocks, with no vertical or horizontal
     surfaces, like a language in which the simplest thought demands
     ornate constructions, useless particles and lengthy
     circumlocutions.  Unlike the more successful patterns of language
     and science, which enable us to face experience boldly or at least
     level-headedly, our system of temporal calculation silently and
     persistently encourages our terror of time.

     ...  It is as though architects had to measure length in feet,
     width in meters and height in ells; as though basic instruction
     manuals demanded a knowledge of five different languages.  It is
     no wonder then that we often look into our own immediate past or
     future, last Tuesday or a week from Sunday, with feelings of
     helpless confusion.  ...

     -- Robert Grudin, `Time and the Art of Living'.

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #278
Difficulty: Easy
A monolithic kernel is an operating system architecture where the entire operating system is working in kernel space.
True or False?

9 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

Bug in Gnu date?

So as I write this today is two days after the clocks go back here in the UK. I have a script that worked last week. Yesterday it developed a bug. I eventually found the culprit is Gnu Date. $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.5 LTS... (10 Replies)
Discussion started by: apmcd47
10 Replies

3. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

4. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

5. UNIX for Advanced & Expert Users

Strange bug crontab command line php / bcompiler

Hello everyone, I have a small problem that I'm stuck for several days and I do not go out. I tell you, I have a php script that I want to run crontab, it uses a compiled bcompiler file. In my php file if(file_exists("php/Alibrary.phb")){ include_once("php/Alibrary.phb"); What I do... (6 Replies)
Discussion started by: nicolas33770
6 Replies

6. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 Replies

7. Shell Programming and Scripting

mv command not found bug

foreach x ( *.foo) echo "move file?" set move=$< if($move == y) then echo "enter new pathname:" set path=$< mv $x $path/$x endif end ok guys, im creating this script so i can move files with *.foo extensions and *.bar... (6 Replies)
Discussion started by: pantelis
6 Replies

8. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. Shell Programming and Scripting

want to get previous date from date command in ksh

I want to get previous date from date command. I am using ksh shell. Exmp: today is 2008.09.04 I want the result : 2008.09.03 Please help. Thanks in advance. (4 Replies)
Discussion started by: rinku
4 Replies

Featured Tech Videos