如何从MySQL中的timestamp数据类型获取日期名称?
2013-01-01 15:00:28
应该返回Tuesday
答案 0 :(得分:23)
SELECT DAYNAME('2013-01-01 10:10:10');
答案 1 :(得分:4)
短日名称示例。这将返回'Tue':
SELECT DATE_FORMAT('2013-01-01 15:00:28','%a') as dayname;
漫长的一天名称示例。这将返回'星期二':
SELECT DAYNAME('2013-01-01 15:00:28') as dayname;
答案 2 :(得分:3)
或者只是使用您正在使用的任何语言对其进行格式化。
让我们说...... PHP:
<?php
$date = '2013-01-01 15:00:28';
$datetime = new DateTime($date);
$formated_date = $datetime->format('l'); // Tuesday
让我们说JavaScript:
var original_date = '2013-01-01 15:00:28';
var day_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
var date_object = new Date(x);
var formated_date = day_names[date_object.getDay()];
// alert or print formated_date