4

如何从 MySQL 中的时间戳数据类型获取日期名称?

2013-01-01 15:00:28应该返回Tuesday

4

3 回答 3

29
SELECT DAYNAME('2013-01-01 10:10:10');
于 2013-01-01T15:25:56.833 回答
6

短日名称示例。这将返回“星期二”:

SELECT DATE_FORMAT('2013-01-01 15:00:28','%a') as dayname;

长天名称示例。这将返回“星期二”:

SELECT DAYNAME('2013-01-01 15:00:28') as dayname;
于 2015-04-17T02:50:47.817 回答
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
于 2013-01-01T15:43:34.737 回答