Page 1 of 1

date(); problem

Posted: Thu Aug 22, 2002 6:49 pm
by qads
i got a date(); problem with in my script:

i need to get today's date: $date = date("d/m/Y");

i need to take 7 days away from $date, so i try $newd = $date - 7;
which offcourse does't work :(.

the reason i need the today's date in d/m/Y format cos that's how it is inserted into the table, not in date field but in text field, cos i have to show it somewhere on my site.

how can i do it?

if you don't understand me then...well...here is simple one...i think

$todays_date = date("d/m/Y");
$todays_date - 7;



please help

Posted: Thu Aug 22, 2002 7:23 pm
by DSM

Code: Select all

//if you are using mysql store $date as a "bigint"
$date = time();

//Day of the year on the Julian Calender
$day = date('yday', $date);
$loose_a_week = "7";

//Day of the year, 7 days ago in Julian Calender
$lastweek = ($day - $loose_a_week);

//Make it fit your display
$date = date('d/m/Y', $lastweek);
Quick tip...

I always store my date/time as a bigint and then use the date() functions to manipulate them into what I need.