2014-12-30 79 views
0
$a= date("Y"); 

什么是数据类型$a:数字或字符串?如果它是一个字符串,我如何获得前一年的PHP?当前年份和以前年份中的PHP

+2

这是一个变量int在PHP使用铸造。您可以将其用作字符串。或者从中减去一个。 '$ last_year =日期( 'Y') - 1'; –

回答

3
echo date("Y",strtotime("-1 year")); //last year "2013" 
echo date("Y");      //current year "2014" 

Also follow this post

And this post

+0

那么,date(“Y”)将当前年份作为一个字符串? –

+0

@Ashutosh是的,请在你的PHP编辑器中使用我的两个例子,看看结果,而不是问问答案。 – Priyank

+0

@AshutoshSaboo:date(“Y”)give“2014” – Priyank

1

您可以使用PHP的relative date/time formats

date('Y', strtotime('last year')); 
+0

那么,date(“Y”)将当前年份作为一个字符串? –

+0

@AshutoshSaboo [是。](http://php.net/manual/en/function.date.php) –

+0

你能帮我解决我的另一个问题:http://stackoverflow.com/questions/27692895/ php-code-required-extracted-number-from-a-string?noredirect = 1#comment43805401_27692895。谢谢! :) –

0
echo date("Y",strtotime("-1 year")); 
+0

@ Rizier123:那么,date(“Y”)将当前年份作为一个字符串? –

+0

@ Rizier123:你还可以帮我解决我的另一个问题:stackoverflow.com/questions/27692895/...。谢谢! :) –

1
<?php 
    echo $a= date("Y")-1; 
    ?> 

http://codepad.org/d0VjiyS5

其不是字符串或数字,我们可以将其定义为字符串或者通过使用(INT)

+0

因此,根据你的日期(“Y”)给出了当前年份“BY DEFAULT”中的数据类型(数字/字符串),还是它将它同时作为一个字符串和一个数字,因此我们可以对日期(“Y”)执行算术和字符串操作? –

+0

你还可以帮我解决我的另一个问题:stackoverflow.com/questions/27692895/...。谢谢! :) –

相关问题