开发者

CURRENT_DATE getting the month and year

I'm currently using the CURRENT_DATE when inserting into my table f开发者_JAVA百科ield for the Date. Pull just the Month and Year two digit month and four digit year (ex $mon = 01 and $year 2010)


see date-and-time-functions

"SELECT MONTH(datefiled) as month, YEAR(datefield) as yeah FROM table"


$date = date("m  Y");
list($mon, $year) = explode(" ", $date);

Basically, the date() function takes a format string (m is the two-digit numerical month, Y is a four-digit year) and produces a string representation of the date. Then you can use explode() to store the split-up values you need in the variables $mon and $year.

Edit: of course, the $date variable is not needed.

list($mon, $year) = explode(" ", date("m Y"));

This will work just as well.


Not sure what you are looking for but if you trying to get the current date in year-month-day notation, the below code should help.

$DATE = date('Y-m-d');

If you are trying to pull the information from the table,

$date_from_table = $row['DateField'];
$DATE = date('Y m', strtotime($date_from_table));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜