Click to See Complete Forum and Search --> : Date Manipulation


Jaelan
01-17-2005, 03:53 PM
Hey guys,
Perhaps my mind is just in sleep mode because it's monday, or perhaps I haven't worked with the date abilities of php before (or both).

I am trying to echo out the dates of the first and last of the week. Example:

Last week was 1-10-2005 to 1-16-2005

I will always be doing the week before the current week. So, is there a function that I can seed with the current date, and subtract 7 days? If not, does anyone have a way to do this, taking into account that the previous days could be in the previous months?

Any help is appreciated,
Jaelan

MstrBob
01-17-2005, 04:01 PM
<?PHP
echo(date('l, F j, Y', (time()-604800)));
?>


Time gives us the amount of seconds since the UNIX epoch. There are 604,800 seconds in a week. The date function takes a UNIX timestamp as a parameter, so we subtract 608,800 seconds from now and get exactly one week from now.

Jaelan
01-17-2005, 04:04 PM
you are awesome!!!

btw, have you done that before, or did you work out how many seconds were in a week?

hehe, thanks again,
Jaelan

MstrBob
01-17-2005, 04:27 PM
Glad it worked. After awhile, one gathers a certain amount of useless information. But it's easily worked out.

Jaelan
01-17-2005, 04:29 PM
It is at that. Oh well, anyway, again, it worked greats and thanks...back to work for me

NogDog
01-17-2005, 04:37 PM
Originally posted by MstrBob
Glad it worked. After awhile, one gathers a certain amount of useless information. But it's easily worked out.
Or you do what I do:

date('l, F j, Y', (time() - (60*60*24*7) ))

:)

MstrBob
01-17-2005, 04:49 PM
Originally posted by NogDog
Or you do what I do:

date('l, F j, Y', (time() - (60*60*24*7) ))

:)

Sure... if you're lazy! :p j/k

Jaelan
01-17-2005, 04:50 PM
which I know I am!

there's no shame here...