我有日期2016-02-17
,我用DATE_FORMAT('2016-02-17', '%M, %D %Y')
像這樣'february, 17th 2016'
顯示它,但我想顯示february, seventeenth 2016
,是Word 17th
,請幫我如何顯示等單詞日期「二月十七2016」用mysql
回答
寫入功能,並顯示答案
function convert_number_to_words($number) {
$hyphen = '-';
$conjunction = ' ';
$separator = ' ';
$negative = 'negative ';
$decimal = ' point ';
$dictionary = array(
0 => 'Zero',
1 => 'One',
2 => 'Two',
3 => 'Three',
4 => 'Four',
5 => 'Five',
6 => 'Six',
7 => 'Seven',
8 => 'Eight',
9 => 'Nine',
10 => 'Ten',
11 => 'Eleven',
12 => 'Twelve',
13 => 'Thirteen',
14 => 'Fourteen',
15 => 'Fifteen',
16 => 'Sixteen',
17 => 'Seventeen',
18 => 'Eighteen',
19 => 'Nineteen',
20 => 'Twenty',
30 => 'Thirty',
40 => 'Fourty',
50 => 'Fifty',
60 => 'Sixty',
70 => 'Seventy',
80 => 'Eighty',
90 => 'Ninety',
100 => 'Hundred',
1000 => 'Thousand',
1000000 => 'Million',
1000000000 => 'Billion',
1000000000000 => 'Trillion',
1000000000000000 => 'Quadrillion',
1000000000000000000 => 'Quintillion'
);
if (!is_numeric($number)) {
return false;
}
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
// overflow
trigger_error(
'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
E_USER_WARNING
);
return false;
}
if ($number < 0) {
return $negative . convert_number_to_words(abs($number));
}
$string = $fraction = null;
if (strpos($number, '.') !== false) {
list($number, $fraction) = explode('.', $number);
}
switch (true) {
case $number < 21:
$string = $dictionary[$number];
break;
case $number < 100:
$tens = ((int) ($number/10)) * 10;
$units = $number % 10;
$string = $dictionary[$tens];
if ($units) {
$string .= $hyphen . $dictionary[$units];
}
break;
case $number < 1000:
$hundreds = $number/100;
$remainder = $number % 100;
$string = $dictionary[$hundreds] . ' ' . $dictionary[100];
if ($remainder) {
$string .= $conjunction . convert_number_to_words($remainder);
}
break;
default:
$baseUnit = pow(1000, floor(log($number, 1000)));
$numBaseUnits = (int) ($number/$baseUnit);
$remainder = $number % $baseUnit;
$string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
if ($remainder) {
$string .= $remainder < 100 ? $conjunction : $separator;
$string .= convert_number_to_words($remainder);
}
break;
}
if (null !== $fraction && is_numeric($fraction)) {
$string .= $decimal;
$words = array();
foreach (str_split((string) $fraction) as $number) {
$words[] = $dictionary[$number];
}
$string .= implode(' ', $words);
}
return $string;
}
echo convert_number_to_words(17);
你可以嘗試這樣的事情:
SELECT
CONCAT(
MONTHNAME(NOW()),
',',
SUBSTRING_INDEX(
SUBSTRING_INDEX('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 31st', ' ' ,DAY(NOW())),
' ',
- 1
),
' ',
YEAR (NOW())
);
注意:用您的日期字段替換NOW()
,並根據需要更新SUBSTRING_INDEX('First Second....
內的文本。
示範:
SET @sampleDate := '2016-02-17';
SELECT
CONCAT(
MONTHNAME(@sampleDate),
', ',
SUBSTRING_INDEX(
SUBSTRING_INDEX('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 31st', ' ' ,DAY(@sampleDate)),
' ',
- 1
),
' ',
YEAR (@sampleDate)
);
爲什麼str_to_date!?! – Strawberry
但它沒有給出確切的輸出,它顯示的數值不是字 –
**但它沒有給出確切的輸出**請你可以更具體一些在這裏分享輸出,就像我說過的,你需要改變'SUBSTRING_INDEX'內的文本,如你想要的...... ..... SUBSTRING_INDEX('第一個第二個第三個第四個第五個第六個第七個第九個第九個第十個第11個第12個第13個第14個第15個第16個第17個第18個19日20日21日22日23日24日25日26日27日28日29日30日31日....'@bhanuavinash – 1000111
的上面的代碼說明什麼1000111貼:
inner substring:
SELECT SUBSTRING_INDEX('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth 11th 12th 13th 14th 15th 16th Seventeenth 18th 19th 20th 21st 22nd 23rd Twentyfourth 25th 26th 27th 28th 29th 30th 31st', ' ' ,DAY('2016-02-17'))
output:
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth 11th 12th 13th 14th 15th 16th Seventeenth 18th 19th 20th 21st 22nd 23rd Twentyfourth
outer substring:
SELECT SUBSTRING_INDEX(
SUBSTRING_INDEX('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth 11th 12th 13th 14th 15th 16th Seventeenth 18th 19th 20th 21st 22nd 23rd Twentyfourth 25th 26th 27th 28th 29th 30th 31st', ' ' ,DAY('2016-02-17')),
' ',
- 1
)
output:
"Seventeenth " if count is -1
"first" if count is 1
"18th Seventeenth " if count is -2
"first second" if count is 2
input:
SELECT
CONCAT(
MONTHNAME('2016-02-17'),
',',
SUBSTRING_INDEX(
SUBSTRING_INDEX('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth 11th 12th 13th 14th 15th 16th Seventeenth 18th 19th 20th 21st 22nd 23rd TwentyFourth 25th 26th 27th 28th 29th 30th 31st', ' ' ,DAY('2016-02-17')),
' ',
- 1
),
' ',
YEAR ('2016-02-17')
);
output:
Feb, Seventeenth 2016
- 1. SQL-Server日期時間格式 - 週一,七月三十一,2000
- 2. 一月\t二月三月\t \t四月\t月\t六月\t七月\t八月\t九月\t十月\t十一月\t十二月\t總和
- 3. moment.js不接受 「31 \\ \\十月2016」 作爲一個日期
- 4. Angularjs - 格式日期(2016 1月13日)
- 5. 顯示日期(4月02)
- 6. 從任何日期格式將日期轉換爲完整日期格式(2016年7月27日星期二)
- 7. 如何顯示第二天的日期?
- 8. Google Chart日曆不會在十一月和十二月運行
- 9. 使用JavaScript顯示日期+ 3個月?
- 10. 如何從「03 - 11月-2016」的日期格式更改爲2016年11月3日
- 11. 如何添加日期與二月閏年的日期或不
- 12. 如何格式化DatePicker以顯示日期格式日/月/年?
- 13. ios - 如何顯示讀取日期「今天,4月14日」?
- 14. 解析日期「2016年1月1日星期五」
- 15. 2016年1月至3月之間查找mySQL中的所有星期日
- 16. Excel單元格將2016年8月轉換爲日期
- 17. mysql:顯示日期時間
- 18. 日期,月份的MySQL日期列
- 19. 在ASP.NET GridView中顯示月份日期
- 20. google.visualization.DataTable顯示錯誤的日期(月+1)
- 21. 顯示日期中的月份名稱
- 22. 日期選擇器不顯示12月
- 23. angularJS顯示1個月日期
- 24. 在Rails中,我如何顯示日期,如2009年12月1日星期一,2009年12月1日
- 25. 如何更改二十七響應式導航斷點
- 26. mysql:按年份和月份(無日期)如何做日期
- 27. dd/MM十月 - 十一月 - 十二月,其他月份dd/M - SimpleDateFormat
- 28. 如何在MySql中將月份換成月份單詞?
- 29. 誰在七月期間有車
- 30. 顯示於七段
@ 1000111,您的評論是沒有意義的。 – Rahul
對不起。第一次看到這個要求,我有點沮喪(:(),並且忍不住自己做了一個這樣的評論。@Rahul – 1000111
@ 1000111,這個問題沒有錯,因爲我看到了,你應該考慮刪除你的評論 – Rahul