I am using a cron job to generate weekly reports on my database. Basically, the report generation script is in PHP. I scheduled a daily cron job.
My week for the reporting starts on Sunday.
I only want the report generation script to generate report, for the previous week from previous Sunday through to previous Monday.
Take for example.
Today is 4 March 2013. When the script runs, it should generate the report for 24 Feb 2013 to 3 March 2013. Tomorrow, when the script runs, it should also only run the report for 24 Feb 2013 to 3 March 2013.
How can I get last Sunday's date, automatically in my script?
Currently, I hard code using the following:
$startDate = strtotime("13 January 2013");
$strStartDate = date ("Y-m-d 00:00:00", $startDate);
$strEndDate = date ("Y-m-d 23:59:00", $startDate + (6*24*60*60));
Any help is much appreciated. Thank you.
For Last Sunday
echo date('Y-m-d',strtotime('last sunday'));
Edited Answer:
For Last Last Sunday
echo date('Y-m-d',strtotime('last sunday -7 days'));
<?php
$date=date("Y-m-d");
echo "Current Date : ".$date."<br>";
echo "last Sunday : ".date('Y-m-d', strtotime($date.'last sunday'));
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With