Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following entry in cron:

0 0 * * * /path/to/

in, there's a call to:

date +%Y%m%d

Even if this executed in zero-time, I'm assuming that the value of date will be for the date after midnight, rather than the date before. Is that correct?

share|improve this question
up vote 4 down vote accepted

Yes, you are correct once the clock hits 00:00:00 date = date +1

However, if you really wanted it to be the day before you could do this in your date command:

date "yesterday" +%Y%m%d

share|improve this answer
OK. The script in question moves the current apache log to a file named with that date, then gzip's it. Would make more sense, therefore, for it to use yesterday's date since most of the requests will be from that date. – Bobby Jack Mar 5 '10 at 18:09
@Bobby: Look at logrotate instead of rolling your own: – Zypher Mar 5 '10 at 18:11

Yes. Computers view 00:00.00 as the start of a new day, so it will be for the date after midnight, not the date before.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.