Get strtotime of a specific time in php

I want to get the timestamp of the day / time, for example

17/12/2014 8pm

      

I am currently doing

$curtime = strtotime(date("Y-m-d H:i:s"));

      

which gives me the current timestamp, but I need to be 8pm.

Any help is greatly appreciated. Thanks in advance.

+3


source to share


2 answers


If you are trying to get the time stamp today at 8pm, it is actually much easier than using it date

, since you can use relative times in strtotime

:

$curtime = strtotime('today 8pm');

      

If you check this with date

:



echo date('Y-m-d H:i:s', $curtime); // Returns 2014-12-17 20:00:00

      

Here's a complete entry on relative date formats that explains how you can plot appropriate relative dates.

+10


source


The best way to do it is date_create_from_format . After choosing the format options, you get something like this:



    $date = date_create_from_format('d/m/Y ga', '17/12/2014 8pm');
    if (!empty($date)) {//returns false if can't create date
        $timestamp = $date->getTimestamp();
        //echo date('d/m/Y H:i:s', $timestamp);
    }

      

+1


source







All Articles