• I have a date stored in a db as -4, 2012, 8 – 1, 15, 00, 00, 00 which is used to create a JS countdown and I am trying to compare this value to the current datetime value to control visibility. I’ve tried to strtotime(‘-4, 2012, 8 – 1, 15, 00, 00, 00’) but it does not work. Any help is appreciated. Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • If you can, you might have to change the string format first to something like:

    strtotime(‘0000-00-00 00:00:00’)

    because it’s not a valid format by default.

    Thread Starter budster2k1

    (@budster2k1)

    I have tried a couple ways to convert the date in php but I cant get them to work is there a php function that would convert the format I have of -4, 2012, 8 – 1, 15, 00, 00, 00 to a date useable in strtotime(‘0000-00-00 00:00:00’) of is there a way to explode the current value and recreate the date using the exploded array values.

    As I know, there isn’t, at least not the format you’ve provided. That looks like a custom format to me.

    If your string uses that exact format, then you just have to explode it using

    https://php.net/manual/en/function.explode.php

    then rejoin the array elements into a string… for example:

    $dateItems = explode(",", "-4, 2012, 8 - 1, 15, 00, 00, 00");

    this will result in

    ( [0] => -4 [1] => 2012 [2] => 8 – 1 [3] => 15 [4] => 00 [5] => 00 [6] => 00 )

    Just join the ones stitching them together as you need, something like:

    $dateString = $dateItems[1] . ‘-‘ . $dateItems[2]… and so on.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Date comparison’ is closed to new replies.