I have :
我有 :
$date = $actualite['date'];
$actualite['date']
is a TIMESTAMP
$ actualite ['date']是一个TIMESTAMP
And I was wondering how can I extract from this timestamp the day, then the month, then the year in 3 variables.
我想知道如何从这个时间戳中提取当天,然后是月份,然后是3个变量中的年份。
Thank you for your help :)
感谢您的帮助 :)
2 个解决方案
#1
23
Use date_parse($actualite['date']);
, which will return an array containing the day, month, year and other items.
使用date_parse($ actualite ['date']);,这将返回一个包含日,月,年和其他项的数组。
http://www.php.net/manual/en/function.date-parse.php
http://www.php.net/manual/en/function.date-parse.php
Example:
例:
<?php
print_r(date_parse("2006-12-12 10:00:00.5"));
?>
Output:
输出:
Array
(
[year] => 2006
[month] => 12
[day] => 12
[hour] => 10
[minute] => 0
[second] => 0
[fraction] => 0.5
[warning_count] => 0
[warnings] => Array()
[error_count] => 0
[errors] => Array()
[is_localtime] =>
)
#2
9
You can extract the values directly within your MySQL query
您可以直接在MySQL查询中提取值
SELECT DAY( <TIMESTAMP_FIELD> ) AS DAY,
MONTH( <TIMESTAMP_FIELD> ) AS MONTH,
YEAR( <TIMESTAMP_FIELD> ) AS YEAR
FROM <TABLE>
#1
23
Use date_parse($actualite['date']);
, which will return an array containing the day, month, year and other items.
使用date_parse($ actualite ['date']);,这将返回一个包含日,月,年和其他项的数组。
http://www.php.net/manual/en/function.date-parse.php
http://www.php.net/manual/en/function.date-parse.php
Example:
例:
<?php
print_r(date_parse("2006-12-12 10:00:00.5"));
?>
Output:
输出:
Array
(
[year] => 2006
[month] => 12
[day] => 12
[hour] => 10
[minute] => 0
[second] => 0
[fraction] => 0.5
[warning_count] => 0
[warnings] => Array()
[error_count] => 0
[errors] => Array()
[is_localtime] =>
)
#2
9
You can extract the values directly within your MySQL query
您可以直接在MySQL查询中提取值
SELECT DAY( <TIMESTAMP_FIELD> ) AS DAY,
MONTH( <TIMESTAMP_FIELD> ) AS MONTH,
YEAR( <TIMESTAMP_FIELD> ) AS YEAR
FROM <TABLE>