Title: PHP Date comparison
Last modified: August 20, 2016

---

# PHP Date comparison

 *  [budster2k1](https://wordpress.org/support/users/budster2k1/)
 * (@budster2k1)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/php-date-comparison/)
 * 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)

 *  [David Choi](https://wordpress.org/support/users/wpthemes777/)
 * (@wpthemes777)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/php-date-comparison/#post-2971505)
 * 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](https://wordpress.org/support/users/budster2k1/)
 * (@budster2k1)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/php-date-comparison/#post-2971595)
 * 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.
 *  [David Choi](https://wordpress.org/support/users/wpthemes777/)
 * (@wpthemes777)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/php-date-comparison/#post-2971596)
 * 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
 * [http://php.net/manual/en/function.explode.php](http://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.

## Tags

 * [datetime](https://wordpress.org/support/topic-tag/datetime/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [time](https://wordpress.org/support/topic-tag/time/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [David Choi](https://wordpress.org/support/users/wpthemes777/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/php-date-comparison/#post-2971596)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
