Forum Moderators: coopster

Message Too Old, No Replies

strtotime vs mktime

any difference?

         

mooger35

9:36 pm on Oct 20, 2007 (gmt 0)

10+ Year Member



date("l, F j, Y", strtotime("20071020"));
date("l, F j, Y", mktime(0,0,0,10,20,2007));

both return the appropriate "Saturday, October 20, 2007"

Is there any reason to use one versus the other?

Habtom

5:16 am on Oct 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In either case you are getting the Unix Timestamp.

strtotime("20071020");
mktime(0,0,0,10,20,2007);

In the way you have used it now, I don't think you need to think much about using one or the other.

But strtotime, gives you a bit of more flexibility when it comes to what you put into it.

To give you an idea, if you need to get the last Sunday's date, you can just use strtotime in the following manner:
echo strtotime("last Sunday"); which is not that easy in mktime.

Coming two weeks:
echo strtotime("+2 week");

The PHP manual has got the details of mktime [php.net] and strtotime [php.net]

Habtom