Rounding a MYSQL datetime to earliest 15 minute interval in milliseconds (PHP)

后端 未结 4 903
情话喂你
情话喂你 2021-01-15 12:14

I\'m fetching a datetime from MYSQL which looks like:

2010-08-11 11:18:28

I need to convert it into the \"floor\" or the earliest 15 minute interval and outp

4条回答
  •  既然无缘
    2021-01-15 12:49

    Would this work? Isn't there some function that would do this better?

    echo floor(strtotime('2010-08-11 11:18:28')/(60*15))*60*15*1000;
    1281505500000
    Wednesday, August 11, 2010 11:15:00 AM
    
    echo floor(strtotime('2010-08-11 11:28:28')/(60*15))*60*15*1000;
    1281505500000
    Wednesday, August 11, 2010 11:15:00 AM
    
    echo floor(strtotime('2010-08-11 00:00:00')/(60*15))*60*15*1000;
    1281465000000
    Wednesday, August 11, 2010 12:00:00 AM
    
    echo floor(strtotime('2010-08-11 23:59:59')/(60*15))*60*15*1000;
    1281550500000
    Wednesday, August 11, 2010 11:45:00 PM
    

提交回复
热议问题