Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中将上月第一天转换为Y-m-d格式_Php_Datetime - Fatal编程技术网

如何在php中将上月第一天转换为Y-m-d格式

如何在php中将上月第一天转换为Y-m-d格式,php,datetime,Php,Datetime,我想以Y-m-d格式获取上个月的第一天 但它不起作用 下面是我的代码 也许您可以这样做: $new_date = date('Y-m-01', strtotime('-1 months')); //should return 2017-08-01 好吧,我的意思是你可以只做日期('Y-m-01',$old\u date\u timestamp)。是的,谢谢。$x=new DateTime('上个月的第一天');echo$x->格式('Y-m-d')

我想以Y-m-d格式获取上个月的第一天

但它不起作用

下面是我的代码


也许您可以这样做:

$new_date = date('Y-m-01', strtotime('-1 months'));   


//should return 2017-08-01

好吧,我的意思是你可以只做
日期('Y-m-01',$old\u date\u timestamp)
。是的,谢谢。
$x=new DateTime('上个月的第一天');echo$x->格式('Y-m-d')