Search code examples
phptimeepoch

php - convert hours : mins to the corresponding epoch time that the value would be today


I have 2 values that i wish to convert to the epoch equivilent that will happen today.

Currently i have; hour - 16 minute - 30

so here i've got half 4 or 16:30 which today would be 1314804607 in epoch

The question is how do I do this conversion each day to get the epoch value of today's 16:30

thanks for your help in advance,

It's that time and im tired :P probably really easy!

Andy


Solution

  • Since mktime defaults the values to the current date/time, we can only override the values you need:

    $hours = 16;
    $minutes = 30;
    
    echo mktime($hours, $minutes);
    

    That will always output the timestamp of 16:30 in your local timezone on the day it was ran...