php - Check if date string is current date -


i'm scraping lot dates check wether today.

so like

if ("apr 9, 2015 18:45" ==  date('y-m-d )) 

how can check if string date like

 apr 9, 2015 18:45 

is today?

list of dates i'm checking

 apr 9, 2015 23:40  apr 9, 2015 18:45  apr 9, 2015 14:18  apr 9, 2015 13:23  apr 9, 2015 12:24  apr 9, 2015 11:00  apr 8, 2015 21:15  apr 8, 2015 21:15  apr 8, 2015 19:35  apr 8, 2015 18:54  apr 8, 2015 17:09  apr 8, 2015 16:41  apr 8, 2015 16:30  apr 8, 2015 15:55  apr 8, 2015 14:15  apr 8, 2015 12:38  apr 8, 2015 12:12  apr 7, 2015 22:30  apr 7, 2015 22:15  apr 7, 2015 18:26 

loop snippet

foreach($gosu->find("//table[@class='simple gamelist medium']/tbody/tr") $gosu_element) {        $gosu_date = mysql_real_escape_string($gosu_element->find("/td[@class='live-in']", 0));     if (date('y-m-d', strtotime($gosu_date)) ==  date('y-m-d')){         echo date('y-m-d', strtotime($gosu_date)) . "<br>";      }   } 

var_dump output:

string(0) "" string(44) "apr 9, 2015 23:40" string(44) "apr 9, 2015 18:45"   string(44) "apr 9, 2015 14:18" string(44) "apr 9, 2015 13:23" string(44) "apr 9, 2015 12:24" string(44) "apr 9, 2015 11:00" string(44) "apr 8, 2015 21:15" string(44) "apr 8, 2015 21:15" string(44) "apr 8, 2015 19:35" string(44) "apr 8, 2015 18:54" string(44) "apr 8, 2015 17:09" string(44) "apr 8, 2015 16:41" string(44) "apr 8, 2015 16:30" string(44) "apr 8, 2015 15:55" string(44) "apr 8, 2015 14:15" string(44) "apr 8, 2015 12:38" string(44) "apr 8, 2015 12:12" string(44) "apr 7, 2015 22:30" string(44) "apr 7, 2015 22:15" string(44) "apr 7, 2015 18:26" 

the strtotime() pretty handy:

if (date('y-m-d', strtotime("apr 9, 2015 18:45")) ==  date('y-m-d')){ 

this result in similar strings. entered compared "2015-04-09" == "2015-04-09".

http://php.net/manual/en/function.date.php

i like:

<?php $dates = array(   "apr 9, 2015 23:40",   "apr 8, 2015 18:45",   "apr 7, 2015 14:18" ); $num_true = 0; $today = date('y-m-d');  for($i=0;$i<=count($dates);$i++){   if(date('y-m-d', strtotime($dates[$i])) != $today){     unset($dates[$i]);   } } // array has dates equal today.  echo "there " . count($dates) . " dates match today:\r\n"; foreach($dates $day){   echo "$day\r\n"; } ?> 

edit: bad logic in statement.


Popular posts from this blog