zoukankan      html  css  js  c++  java
  • MySQL中实现中文格式日期获取

    MySQL 代码

    
    -- 数字年份转中文
    CREATE function yearconvert(in_date VARCHAR(20))
    RETURNS VARCHAR(20)
    BEGIN
    DECLARE conusestr VARCHAR(20);
    SET conusestr='〇一二三四五六七八九';
    
    return (CONCAT(SUBSTR(conusestr,SUBSTR(in_date,1,1)+1,1),SUBSTR(conusestr,SUBSTR(in_date,2,1)+1,1),
    		SUBSTR(conusestr,SUBSTR(in_date,3,1)+1,1),SUBSTR(conusestr,SUBSTR(in_date,4,1)+1,1),'年'));
    END$$
    delimiter ;
    
    -- 数字月份转中文
    delimiter $$
    CREATE FUNCTION monthconvert(in_date VARCHAR(20))
    RETURNS VARCHAR(20)
    BEGIN
    DECLARE conusestr VARCHAR(20);
    SET conusestr='一二三四五六七八九';
    CASE SUBSTR(in_date,1,1)
    	WHEN '0' THEN
    		RETURN (CONCAT(SUBSTR(conusestr,SUBSTR(in_date,2,1),1),'月'));
    	ELSE
    		 RETURN (CONCAT('十',SUBSTR(conusestr,SUBSTR(in_date,2,1),1),'月'));	
    END CASE;
    END $$
    delimiter ;
    
    -- 数字日转中文
    delimiter $$
    CREATE FUNCTION dayconvert(in_date VARCHAR(20))
    RETURNS VARCHAR(20)
    BEGIN
    DECLARE conusestr VARCHAR(20);
    SET conusestr='一二三四五六七八九';
    CASE SUBSTR(in_date,1,1)
    	WHEN '0' THEN
    		RETURN (CONCAT(SUBSTR(conusestr,SUBSTR(in_date,2,1),1),'日'));
    	WHEN '1' THEN
    		RETURN (CONCAT('十',SUBSTR(conusestr,SUBSTR(in_date,2,1),1),'日'));	
    	WHEN '2' THEN
    		RETURN (CONCAT('二十',SUBSTR(conusestr,SUBSTR(in_date,2,1),1),'日'));
    	WHEN '3' THEN
    		RETURN (CONCAT('三十',SUBSTR(conusestr,SUBSTR(in_date,2,1),1),'日'));
    	ELSE
    		 RETURN '无效';
    END CASE;
    END $$
    delimiter ;
    

    函数调用

    select yearconvert(2019);
    select monthconvert(11);
    select dayconvert(21);
    
  • 相关阅读:
    [luoguP1437] [HNOI2004]敲砖块(DP)
    [luoguP2073] 送花(set)
    [luoguP1783] 海滩防御(二分 || 最短路 || 最小生成树)
    [luoguP3068] [USACO13JAN]派对邀请函Party Invitations(stl大乱交)
    [luoguP1849] [USACO12MAR]拖拉机Tractor(spfa)
    数组
    String
    学不会的JVM
    异常
    反射
  • 原文地址:https://www.cnblogs.com/wzbury/p/13589677.html
Copyright © 2011-2022 走看看