[英]php date usage for today and yesterday
I am a beginner for php. 我是php的初学者。 I am trying to integrate an XML API to my system.
我正在尝试将XML API集成到我的系统中。 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. 我找不到如何描述。
You can simply use strtotime()
call like so: 您可以像这样简单地使用
strtotime()
调用:
$today = date('Y-m-d', strtotime('today') );
$yesterday = date('Y-m-d', strtotime('1 day ago') );
$Start_Date=date('d.m.Y',strtotime("-1 days"));
$End_Date = date('d.m.y', strtotime('today') );
PHP strtotime() function helps in this: PHP strtotime()函数可以帮助您:
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('Ym-d',strtotime('yesterday')) gives you yesterday's date !! 是的,它简单的date('Ym-d',strtotime('yesterday'))给您昨天的日期!
ref: http://php.net/manual/en/function.strtotime.php 参考: http : //php.net/manual/en/function.strtotime.php
int strtotime ( string $time [, int $now = time() ] )
$time = A date/time string. $ time =日期/时间字符串。 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. $ now =这是时间戳的可选参数,用作计算相对日期的基础。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.