Discussion:
busybox date to show yesterday's date
Ming-Ching Tiew
2009-04-06 21:26:03 UTC
Permalink
This works for gnu date :-

# date -d yesterday

Does not work for busybox

# date -d yesterday
date: invalid date 'yesterday'

Short of putting gnu date on the system, anyone has a nice workaround for it ?

Regards
walter harms
2009-04-08 10:53:04 UTC
Permalink
Post by Ming-Ching Tiew
This works for gnu date :-
# date -d yesterday
Does not work for busybox
# date -d yesterday
date: invalid date 'yesterday'
Short of putting gnu date on the system, anyone has a nice workaround for it ?
bb has (intentionaly) no date interpreter build-in. a fancy trick i used some time ago was
env TZ="UTC+24" date
but beware some implemantation check the TZ very carefully and ignore values like TZ=UTZ+48.

re,
wh
Ralf Friedl
2009-04-08 11:14:40 UTC
Permalink
Post by Ming-Ching Tiew
This works for gnu date :-
# date -d yesterday
Does not work for busybox
# date -d yesterday
date: invalid date 'yesterday'
Short of putting gnu date on the system, anyone has a nice workaround for it ?
Regards
You can use this:

./busybox date -D %s -d $(( $(./busybox date +%s) - 86400 ))

86400 = 24*60*60 = 1 day

Regards
Ralf Friedl
Alessandro Rubini
2009-04-08 11:21:06 UTC
Permalink
Post by Ming-Ching Tiew
# date -d yesterday
date: invalid date 'yesterday'
Short of putting gnu date on the system, anyone has a nice
workaround for it ?
Before discovering "-d yesterday" I wrote this simple program attached.
It's definitely shorter than GNU date.

/alessandro
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yesterday.c
Type: text/x-csrc
Size: 530 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20090408/8a05171c/attachment.c>
Ming-Ching Tiew
2009-04-08 12:30:00 UTC
Permalink
Post by Ming-Ching Tiew
Post by Ming-Ching Tiew
This works for gnu date :-
# date -d yesterday
Does not work for busybox
# date -d yesterday
date: invalid date 'yesterday'
Short of putting gnu date on the system, anyone has a
nice workaround for it ?
Post by Ming-Ching Tiew
Regards
./busybox date -D %s -d $(( $(./busybox date +%s) - 86400
))
86400 = 24*60*60 = 1 day
This is exactly what I need.

Thanks.
walter harms
2009-04-08 14:12:00 UTC
Permalink
Post by Ming-Ching Tiew
Post by Ming-Ching Tiew
Post by Ming-Ching Tiew
This works for gnu date :-
# date -d yesterday
Does not work for busybox
# date -d yesterday
date: invalid date 'yesterday'
Short of putting gnu date on the system, anyone has a
nice workaround for it ?
Post by Ming-Ching Tiew
Regards
./busybox date -D %s -d $(( $(./busybox date +%s) - 86400
))
86400 = 24*60*60 = 1 day
This is exactly what I need.
Thanks.
please beware that you need to know your needed precission. We have leap seconds
and if your system needs to be precise by one second you may fail unexpected.

re,
wh
Denys Vlasenko
2009-04-12 15:18:56 UTC
Permalink
Post by Ming-Ching Tiew
This works for gnu date :-
# date -d yesterday
Does not work for busybox
# date -d yesterday
date: invalid date 'yesterday'
coreuituls have 10+ implementation of lexic parser of textual date.
We need far more compact version.
--
vda

Loading...