zoukankan      html  css  js  c++  java
  • mysql日期格式化

    mysql日期格式化
    DATE_FORMA T(date, format) 根据格式串format 格式化日期或日期和时间值date,返回结果串。
    可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值,以便得到所希望的格式。
    根据format字符串格式化date值:

    %S, %s 两位数字形式的秒( 00,01, . . ., 59)
    %i 两位数字形式的分( 00,01, . . ., 59)
    %H 两位数字形式的小时,24 小时(00,01, . . ., 23)
    %h, %I 两位数字形式的小时,12 小时(01,02, . . ., 12)
    %k 数字形式的小时,24 小时(0,1, . . ., 23)
    %l 数字形式的小时,12 小时(1, 2, . . ., 12)
    %T 24 小时的时间形式(h h : m m : s s)
    %r 12 小时的时间形式(hh:mm:ss AM 或hh:mm:ss PM)
    %p AM 或P M
    %W 一周中每一天的名称( S u n d a y, Monday, . . ., Saturday)
    %a 一周中每一天名称的缩写( Sun, Mon, . . ., Sat)
    %d 两位数字表示月中的天数( 00, 01, . . ., 31)
    %e 数字形式表示月中的天数( 1, 2, . . ., 31)
    %D 英文后缀表示月中的天数( 1st, 2nd, 3rd, . . .)
    %w 以数字形式表示周中的天数( 0 = S u n d a y, 1=Monday, . . ., 6=Saturday)
    %j 以三位数字表示年中的天数( 001, 002, . . ., 366)
    % U 周(0, 1, 52),其中Sunday 为周中的第一天
    %u 周(0, 1, 52),其中Monday 为周中的第一天
    %M 月名(J a n u a r y, February, . . ., December)
    %b 缩写的月名( J a n u a r y, February, . . ., December)
    %m 两位数字表示的月份( 01, 02, . . ., 12)
    %c 数字表示的月份( 1, 2, . . ., 12)
    %Y 四位数字表示的年份
    %y 两位数字表示的年份
    %% 直接值“%”

    select date_format(日期字段,’%Y-%m-%d’) as ‘日期’ from dual;

    ---------------------------------------------------------------------

    !2020-03-24 08:21:11
    drop procedure if exists citydata.shiyw11_u_5user9;
    delimiter //
    create procedure citydata.shiyw11_u_5user9()
    begin
    call citydata.shiyw11_user_svc();
    set @SqlStr = ' select count(1) into @i from citydata.u_5user ; ';
    prepare SqlStr from @SqlStr;
    execute SqlStr;
    deallocate prepare SqlStr;
    select @i;
    end;
    //
    DELIMITER ;
    call citydata.shiyw11_u_5user9();

    ----2019-10-24 18:42:53------------
    drop procedure if exists test20191024;
    DELIMITER //
    create procedure test20191024()
    begin
    set @vv = ' xxxx 完美输出mysql完美输出 ; ';
    select @vv;
    end;
    //
    DELIMITER ;
    call test20191024();
    ----2019-10-24 18:42:53------------


    ---------------------------------------------------------------------


    mysql -urot -psyw

    show databases;
    show tables;
    use test;
    Commit;
    update `stu` a set a.age=9;
    update `stu` a set a.sex=1;
    update `stu` a set a.mark='x1';
    Commit;
    select @rownum:=@rownum+1 as rw,a.* from stu a,(select @rownum:=1) t;
    Commit;
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (2, '信息12', '9', '1', '信息1', '13452', 'x1', 'https://www.baidu.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (3, '菜鸟', '9', '1', 'CN', '23453', 'x1', 'https://www.runoob.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (4, '变成', '9', '1', 'DD', '33451', 'x1', 'https://c.runoob.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (5, '教程', '9', '1', 'FF', '53454', 'x1', 'https://127.0.0.1:3000');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (6, '查找', '9', '1', 'AA', '13422', 'x1', 'https://localhost:3000');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (7, '百度', '9', '1', 'AA', '13452', 'x1', 'https://www.baidu.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (8, '菜鸟', '9', '1', 'CN', '23453', 'x1', 'https://www.runoob.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (9, '变成', '9', '1', 'DD', '33451', 'x1', 'https://c.runoob.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (10, '教程', '9', '1', 'FF', '53454', 'x1', 'https://127.0.0.1:3000');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (11, '查找', '9', '1', 'AA', '13422', 'x1', 'https://localhost:3000');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (12, '百度', '9', '1', 'AA', '13452', 'x1', 'https://www.baidu.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (13, '菜鸟', '9', '1', 'CN', '23453', 'x1', 'https://www.runoob.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (14, '变成', '9', '1', 'DD', '33451', 'x1', 'https://c.runoob.com');
    INSERT INTO `stu`(`id`, `name`, `age`, `sex`, `username`, `info`, `mark`, `address`) VALUES (15, '教程', '9', '1', 'FF', '53454', 'x1', 'https://127.0.0.1:3000');
    Commit;
    Commit;


    --------------------------------

    drop table if exists citydata.d00_9guhua ;
    create table citydata.d00_9guhua as
    select DEVELOP_DEPART_ID DEPART_ID,b.product_id,b.product_name,count(*) c,
    sum(case when net='21' and DATE_FORMAT(KAI_DATE,'%Y%m%d')=DATE_FORMAT(now()-1,'%Y%m%d') then 1 else 0 end) day_ge50,
    sum(case when net='21' and DATE_FORMAT(KAI_DATE,'%Y%m')=DATE_FORMAT(now()-1,'%Y%m') then 1 else 0 end) mon_ge50,
    sum(case when net<'21' and DATE_FORMAT(KAI_DATE,'%Y%m%d')=DATE_FORMAT(now()-1,'%Y%m%d') then 1 else 0 end) day_ge33,
    sum(case when net<'21' and DATE_FORMAT(KAI_DATE,'%Y%m')=DATE_FORMAT(now()-1,'%Y%m') then 1 else 0 end) mon_ge33,
    DATE_FORMAT(now(),'%Y%m%d%H%i%s') timedo
    FROM citydata.dd_6jungong b GROUP BY b.product_id,b.product_name,DEVELOP_DEPART_ID
    ;

    -------------------------------------

    1DATE_FORMAT(date,format)函数

    format格式如下

    ---------------------

  • 相关阅读:
    NOIP1998提高组——挖地雷
    模板——EXBSGS
    vue 知识点
    jq_js
    ruby 基础知识(一)
    idea maven pom配置文件
    .net core dapper (5)
    .net core dapper (4)
    .net core dapper (3)
    .net core dapper (2)
  • 原文地址:https://www.cnblogs.com/xinxihua/p/12563844.html
Copyright © 2011-2022 走看看