I am testing a script and need to change the system date to Nov 30 2009. I cannot seem to find a way to do this other than TZ command but it does not seem to work correctly.
I tried TZ=GMT+168 date but it is returning todays date
Mon Dec 7 19:48:11 GMT 2009
...instead of Nov 30 2009
I tried TZ=GMT+24 date and it does return yesterdays date
Sun Dec 6 19:52:30 GMT 2009
I tried TZ=GMT+144 date and it does return date 6 days ago
Tue Dec 1 19:51:23 GMT 2009
IF you set the system date using the date command ( assuming you are not running ntpd or xtnpd) then that will change the system time.
Anything else is just sort of silly. You can use TZ to mess around with a few days, as you have discovered, but it is NOT changing the system date: that is set as the number of seconds since Jan 1 1970. To truly change the date you have to reset system time with the date command - which is NOT a great idea. crontab can get confused, for example.
What are you really trying to accomplish - answer does not include not playing with TZ?
I am trying to test some logic that relies on the unix date being the last calendar day of the month. Obviously if I run this now the system date will be Dec 7 2009 - I want to test the script when the date is Nov 30 2009 or Dec 31 2009.
You will have to have a development box. We have a specific box named "timewarp" for just this kind of stuff. There are no cron jobs, no at jobs, and it is setup with no ntpd.
I personally have not tried this because our Sun OS versions are old:
create a Solaris zone with its own internal UTC setting - on Solaris 10g.
You should have a development environment at your work as well. Or maybe create a desktop one using Virtual Box - if you have to test time/date dependent code.
You are not actually testing time/date dependent code otherwise.