Forum Moderators: coopster

Message Too Old, No Replies

substract minutes with mktime

         

hanyaz

9:09 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



Hello how can i substract minutes with mktime ? Tried this but does not seem to work :
$date= date("Ymd",mktime(0,0,0,date("m"),date("d")-$number,date("Y")));

mooger35

9:38 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



You are subtracting days, not minutes.

mktime [us2.php.net]

To subtract minutes you'd subtract from the second argument.

[edited by: mooger35 at 9:45 pm (utc) on June 17, 2009]

hanyaz

9:44 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



but if i want minutes ? I tried this but does not seem to work :
$date= date("Ymd",mktime(0,date("i")-30,date("s"),date("m"),date("d"),date("Y")));

mooger35

9:48 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



Sure it does... but you aren't outputting it. You are showing "Ymd" (ex. 20090617). So unless you are just past midnight you won't see any difference.

Sorry... edit that.

If you are subtracting 30 from minutes and using 0 for hour then you would get the following.

current minutes 0 -> 29 = yesterday's date
current minutes 30 -> 59 = today's date

hanyaz

9:57 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



$number = 3;
$date= date("Ymd",mktime(date("H"),date("i")-$number,date("s"),date("m"),date("d"),date("Y")));

does not work for me...

mooger35

10:03 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



That outputs today's date minus 3 minutes. So unless you are between midnight and up to 3 minutes past you won't see any change to the date format you chose.

Change "Ymd" to "Ymd H:i:s" and you'll see the difference. It will output today's date (and time) minus 3 minutes.