Unix command

neilm

Golden Member
Aug 25, 2002
1,108
0
0
Is it safe to use:
TZ=+24 date

Basically this outputs yesterdays date, just wondering is it safe for leap years, new years, and all that?

(PS. Dunno how to unattach code so ignore the below)
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
First of all, I think that will be highly dependent on your platform. On osx, setting TZ=+# seems to output the current date UTC, regardless of what # is. On openbsd it makes the adjustment as you might expect.

But you also have to take into account that this only really works in UTC. To get yesterday's date here (Ontario) I have to use TZ=+29, but I don't think that'll work the other half of the year (I think it should be +30, but I haven't thought about it long enough).
 

neilm

Golden Member
Aug 25, 2002
1,108
0
0
I don't have the GNU date at work, so forced to come up with an alternative solution.

When you talk about daylight savings, where you have to up the hour the next half a year, I don't get it? Surely you can amend the TZ=+# to be anywhere in the 24hour period, no?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Are you stuck using shell? Date manipulation isn't too bad in perl so that might be an option.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: neilm
When you talk about daylight savings, where you have to up the hour the next half a year, I don't get it? Surely you can amend the TZ=+# to be anywhere in the 24hour period, no?
Sure, but do you want to amend it every 6 months?
 

jfall

Diamond Member
Oct 31, 2000
5,975
2
0
this is much easier:

date -d "1 day ago"


BSD?

YESTERDAY=`expr \`date +%s\` - 86400`
date -r $YESTERDAY


edit, no gnu date :(

 

neilm

Golden Member
Aug 25, 2002
1,108
0
0
Originally posted by: kamper
Originally posted by: neilm
When you talk about daylight savings, where you have to up the hour the next half a year, I don't get it? Surely you can amend the TZ=+# to be anywhere in the 24hour period, no?
Sure, but do you want to amend it every 6 months?

That's what I mean, I don't get why you would have too.

Why not just keep it inline with timezone like so:
TZ=EST+29 date

...and use a cronjob to trigger it during the mid day? Not sure how timezone can affect the date, can someone explain?

Originally posted by: jfall
this is much easier:

date -d "1 day ago"


BSD?

YESTERDAY=`expr \`date +%s\` - 86400`
date -r $YESTERDAY


edit, no gnu date :(
Can't use any of those unfortunately, or this would be wee buns.

Originally posted by: Nothinman
Are you stuck using shell? Date manipulation isn't too bad in perl so that might be an option.
Yep I can use perl, and I think that would be a better alternative.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: neilm
Originally posted by: kamper
Originally posted by: neilm
When you talk about daylight savings, where you have to up the hour the next half a year, I don't get it? Surely you can amend the TZ=+# to be anywhere in the 24hour period, no?
Sure, but do you want to amend it every 6 months?
That's what I mean, I don't get why you would have too.

Why not just keep it inline with timezone like so:
TZ=EST+29 date

...and use a cronjob to trigger it during the mid day? Not sure how timezone can affect the date, can someone explain?
I'm probably just confused about this, but am I not 5 hours off UTC in the winter and 6 hours off in the summer? Isn't that the whole point of daylight savings time? I always get very confused when programming with dates. :confused: