Tino
Tino

Reputation: 3368

mktime equivalent in php 5.3

Hi I just updated to php 5.3.

I use mktime() in a script:

$DateSec = mktime($Hour, $Minutes, $Seconds, $Month, $Day, $Year, 0);

What would be the equivalent function in PHP 5.3?

Upvotes: 1

Views: 2826

Answers (3)

sylvain
sylvain

Reputation: 1971

you could also use

strtotime('2015-04-30 17:00:00');

which could be combined with date function to mimic mktime defaults like this :

strtotime(date('Y').'-04-30');

Upvotes: 0

SDC
SDC

Reputation: 14222

As others have said, mktime() does still work in PHP 5.3, and it does still have a place. But personally, I much prefer to use the new DateTime classes for all my date handling. They are significantly better all round than the old functions.

Take a look at the DateTime class manual page. It has some stuff that might interest you.

For example, this is how you would replace mktime() using the new OO methods:

$date = new DateTime();    
$date->setDate($year, $month, $day);
$date->setTime($hour, $mins, $secs);

But this might also be of interest:

$date = DateTime::createFromFormat('Y-m-d H:i:s', '2009-02-15 15:16:17')

Hope that helps.

Upvotes: 0

Jonathan Muller
Jonathan Muller

Reputation: 7516

https://www.php.net/manual/fr/function.mktime.php

You use it well, just remove the last argument.

mktime($Hour, $Minutes, $Seconds, $Month, $Day, $Year);

Is not deprecated.

If you want to use specific timezones, look at this: https://www.php.net/manual/en/function.date-default-timezone-set.php

Upvotes: 3

Related Questions