Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

Yesterday and today

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 31, 2003
posts: 919
votes: 1


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];
}
10:23 am on Apr 27, 2017 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 20, 2017
posts:334
votes: 73


$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.
10:51 am on Apr 27, 2017 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 20, 2017
posts:334
votes: 73


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.