Forum Moderators: coopster

Message Too Old, No Replies

$date = date("Y-m-d", strtotime(""));

Yesterday and today

         

textex

2:35 am on Apr 27, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How would I code a start time of yesterday into today. I need to run a cron job of data from say 10pm - 6am the next morning.

Also need help coding:
$res = mysql_query("select distinct email from respawn where date <= '$date ' and date >= '$date '");
while($row = mysql_fetch_row($res)) {
$data[] = $row[0];
}

Peter_S

10:23 am on Apr 27, 2017 (gmt 0)

5+ Year Member Top Contributors Of The Month



$today = date( 'Y-m-d' ) ;
$yesterday = date ( 'Y-m-d' , time ( ) - 60 * 60 * 24 ) ;
or
$today = date( 'Y-m-d' , strtotime ( 'now' ) ) ;
$yesterday = date ( 'Y-m-d' , strtotime ( '-1 days' ) ) ;

I did not understand your second question. but don't use the mysql_xxx functions, the are depreciated since a long time. Instead use the mysqli_xxx (with a "i") or the PDO class.

Peter_S

10:51 am on Apr 27, 2017 (gmt 0)

5+ Year Member Top Contributors Of The Month



Of course, instead of "60 * 60 * 24" you can put "86400" , but I prefer to leave the formula, so that it talks by itself 60 seconds * 60 minutes * 24 hours. And this is not causing any performance loss, since the op cache of PHP will optimize it and cache the value.