Reputation: 699
I am a beginner for php. I am trying to integrate an XML API to my system. Calling code is
$XML = simplexml_load_file('http://my.mydomain.com/stats/report.xml?api_key=XXXXXXXX&start_date='.date('Y-m-d').'&end_date='.date('Y-m-d'));
What I need to do is;
I could not find how to describe.
Upvotes: 0
Views: 347
Reputation: 227
PHP strtotime() function helps in this:
You could use
$XML = simplexml_load_file('http://my.mydomain.com/stats/report.xml?api_key=XXXXXXXX&start_date='.date('Y-m-d',strtotime('yesterday')).'&end_date='.date('Y-m-d',strtotime('yesterday'));
Yes its that simple, date('Y-m-d',strtotime('yesterday')) gives you yesterday's date !!
ref: http://php.net/manual/en/function.strtotime.php
int strtotime ( string $time [, int $now = time() ] )
$time = A date/time string. Valid formats are explained in Date and Time Formats.
$now = This is an optional parameter for the timestamp which is used as a base for the calculation of relative dates.
Upvotes: 2
Reputation: 619
$Start_Date=date('d.m.Y',strtotime("-1 days"));
$End_Date = date('d.m.y', strtotime('today') );
Upvotes: 2
Reputation: 80639
You can simply use strtotime()
call like so:
$today = date('Y-m-d', strtotime('today') );
$yesterday = date('Y-m-d', strtotime('1 day ago') );
Upvotes: 2