How to print out "n" days ago's year, month and day?
Interesting uh?
For example, 2 days ago's date is 2011 Feb 8th. This is not a homework... thanks! |
Code:
date -d '2 days ago' |
I was just going to write what ta0kira wrote. The GNU date command is awesome. Anyway, in C, you can do
Code:
#include <stdio.h> The call to mktime both normalizes the split date, and returns the resulting time in the base time_t format, seconds since epoch. See the ctime, localtime, and mktime man page for details. This is in the POSIX standard, and should work as-is on all sane operating systems. It shouldn't be too difficult to add parameter parsing to the above, to get exactly what you need. Nominal Animal |
Code:
$ ruby -r'date' -e 'print (DateTime.now - 48/24).strftime("%Y/%m/%d")' |
All times are GMT -5. The time now is 09:19 AM. |