当前位置: 首页 > news >正文

电子商务网站建设与管理思考与练习/小程序开发工具

电子商务网站建设与管理思考与练习,小程序开发工具,树莓派做的网站,深圳集团网站建设报价STR_TO_DATE函数用于将字符串转变为日期/时间值,与DATE_FORMAT函数的作用是相反的。这个函数是Mysql的日期时间函数,对此,LightDB做了兼容,详细的文档可参考Mysql官网文档str_to_date。 函数说明: -- srt:要格式化为…

STR_TO_DATE函数用于将字符串转变为日期/时间值,与DATE_FORMAT函数的作用是相反的。这个函数是Mysql的日期时间函数,对此,LightDB做了兼容,详细的文档可参考Mysql官网文档str_to_date。

函数说明:

-- srt:要格式化为日期的字符串(输入字符串) 
-- format:要使用的格式字符串
-- 返回值可以是DATETIME,DATE,TIME类型。返回何种类型由参数决定
STR_TO_DATE(str,format)

其中format格式化字符串含义说明如下:

SpecifierDescription
%aAbbreviated weekday name (Sun…Sat)
%bAbbreviated month name (Jan…Dec)
%cMonth, numeric (0…12)
%DDay of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%dDay of the month, numeric (00…31)
%eDay of the month, numeric (0…31)
%fMicroseconds (000000…999999)
%HHour (00…23)
%hHour (01…12)
%IHour (01…12)
%iMinutes, numeric (00…59)
%jDay of year (001…366)
%kHour (0…23)
%lHour (1…12)
%MMonth name (January…December)
%mMonth, numeric (00…12)
%pAM or PM
%rTime, 12-hour (hh:mm:ss followed by AM or PM)
%SSeconds (00…59)
%sSeconds (00…59)
%TTime, 24-hour (hh:mm:ss)
%UWeek (00…53), where Sunday is the first day of the week; WEEK() mode 0
%uWeek (00…53), where Monday is the first day of the week; WEEK() mode 1
%VWeek (01…53), where Sunday is the first day of the week; WEEK() mode 2; used with %X
%vWeek (01…53), where Monday is the first day of the week; WEEK() mode 3; used with %x
%WWeekday name (Sunday…Saturday)
%wDay of the week (0=Sunday…6=Saturday)
%XYear for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%xYear for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%YYear, numeric, four digits
%yYear, numeric (two digits)
%%A literal % character
%xx, for any “x” not listed above

根据str以及format输出日期/时间类型,其中如果含有日期以及时间,则返回DATETIME类型,如果仅含有日期则返回DATE类型,如果仅含有时间则返回TIME类型。示例如下:

  • 包含日期以及时间:
-- 需要在mysql模式下
postgres@mysql=# show lightdb_dblevel_syntax_compatible_type ;lightdb_dblevel_syntax_compatible_type 
----------------------------------------MySql
(1 row)postgres@mysql=# select str_to_date('2022-05-26 11:30:59','%Y-%m-%d %H:%i:%s');str_to_date     
---------------------2022-05-26 11:30:59
(1 row)postgres@mysql=# SELECT STR_TO_DATE('Monday 7th November 2022 13:45:30','%W %D %M %Y %T');str_to_date     
---------------------2022-11-07 13:45:30
(1 row)postgres@mysql=# SELECT STR_TO_DATE('Nov 05 2022 02:30 PM','%b %d %Y %h:%i %p');str_to_date     
---------------------2022-11-05 14:30:00
(1 row)
  • 仅含日期:
postgres@mysql=# select str_to_date('2022-05-26','%Y-%m-%d');str_to_date 
-------------2022-05-26
(1 row)postgres@mysql=# select str_to_date('August,5,2022', '%M,%e,%Y');str_to_date 
-------------2022-08-05
(1 row)postgres@mysql=# SELECT str_to_date('04/30/2004', '%m/%d/%Y');str_to_date 
-------------2004-04-30
(1 row)
  • 仅含时间
postgres@mysql=# select str_to_date('09:00:59', '%h:%i:%s');str_to_date 
-------------09:00:59
(1 row)postgres@mysql=# select str_to_date('10,40,50', '%h,%i,%s');str_to_date 
-------------10:40:50
(1 row)postgres@mysql=# SELECT STR_TO_DATE('09:30:17a','%h:%i:%s');str_to_date 
-------------09:30:17
(1 row)

另外,在Mysql中支持sql_mode,在no_zero_date下,不允许出现日期为zero,对此,在LightDB中,支持lightdb_sql_mode参数,在LightDB中,可设置

postgres@mysql=# show lightdb_sql_mode ;lightdb_sql_mode 
------------------(1 row)
-- 设置 lightdb sql mode 为no_zero_date
postgres@mysql=# set lightdb_sql_mode = 'no_zero_date';
SET
postgres@mysql=# show lightdb_sql_mode ;lightdb_sql_mode 
------------------no_zero_date
(1 row)

在lightdb sql mode为no_zero_date时,以下示例,返回NULL:

-- 非法日期
postgres@mysql=# SELECT str_to_date('9','%d');str_to_date 
-------------(1 row)
-- 非法日期
postgres@mysql=# SELECT str_to_date('1999','%Y%d');str_to_date 
-------------(1 row)postgres@mysql=# SELECT STR_TO_DATE('2022-12-11 11:12:26','%Y-%m');str_to_date 
-------------(1 row)

在LightDB中,如果lightdb_sql_mode没有设置no_zero_date时,返回的结果与mysql不同,因为LightDB不会返回一个类似1999-0-0这样不存在的非法日期,会默认返回一个合法日期。

set lightdb_sql_mode to '';
show lightdb_sql_mode;lightdb_sql_mode 
------------------(1 row)SELECT str_to_date('9','%m');   str_to_date  
---------------0001-09-01 BC
(1 row)SELECT str_to_date('1999','%Y%d');str_to_date 
-------------1999-01-01
(1 row)SELECT str_to_date('1999','%Y');    -- pg return 1999-01-01, mysql return 1999-00-00str_to_date 
-------------1999-01-01
(1 row)

在LightDB中,不支持str_to_date函数应用绑定变量,从用户使用的角度也不推荐这么用。同时,LightDB的错误处理更加准确严格,示例如下:

-- return error in lightdb, return null in mysql
set lightdb_sql_mode to 'no_zero_date';
show lightdb_sql_mode;lightdb_sql_mode 
------------------no_zero_date
(1 row)SELECT str_to_date('13','%m');
ERROR:  date/time field value out of range: "13"
SELECT str_to_date('32','%d');
ERROR:  date/time field value out of range: "32"
SELECT STR_TO_DATE('61','%s');
ERROR:  date/time field value out of range: "61"
SELECT STR_TO_DATE('25','%H');
ERROR:  date/time field value out of range: "25"
SELECT STR_TO_DATE('61','%i');
ERROR:  date/time field value out of range: "61"
set lightdb_sql_mode to '';
show lightdb_sql_mode;lightdb_sql_mode 
------------------(1 row)SELECT str_to_date('13','%m');
ERROR:  date/time field value out of range: "13"
SELECT str_to_date('32','%d');
ERROR:  date/time field value out of range: "32"
SELECT STR_TO_DATE('61','%s');
ERROR:  date/time field value out of range: "61"
SELECT STR_TO_DATE('25','%H');
ERROR:  date/time field value out of range: "25"
SELECT STR_TO_DATE('61','%i');
ERROR:  date/time field value out of range: "61"
-- test return null in any sql_mode
SELECT str_to_date(null ,'%Y-%m-%d');str_to_date 
-------------(1 row)
http://www.jmfq.cn/news/4939975.html

相关文章:

  • 新会网站建设/seo搜索引擎优化工资薪酬
  • 南宁企业网站制作哪家好/网站排名优化+o+m
  • 怎样建设网站优化/怎么建立网站?
  • 吉安高端网站建设公司/郑州谷歌优化外包
  • 企业设计网站公司哪家好/小红书网络营销策划方案
  • 做淘宝客要建网站吗/免费发帖的网站
  • asp双语企业网站源码/广州seo外包
  • 电商网站图片处理/如何做好推广
  • 做图网站有哪些东西吗/怎么制作一个网站首页
  • 怀化政法网站/专业的google推广公司
  • 肥城做网站tahmwlkj/推广平台排名
  • 做视频网站软件有哪些/百度关键词排名原理
  • 企业网站搭建程序/城关网站seo
  • 教务管理系统学生登录入口/武汉网站seo公司
  • 内江市住房和城乡建设局网站/快速优化排名公司推荐
  • 网站建设制作 武汉/友情链接是什么意思
  • 怎么自己建立一个网站后台/深圳今天重大事件新闻
  • 广州微信网站开发公司/网站关键词排名服务
  • 简述网站设计要遵循哪些原则/太原网站推广排名
  • 网站搬家教程/小程序开发公司哪里强
  • 自己怎么做免费网站空间/合肥网
  • 购物网站要多少钱/好看的网页设计作品
  • 网站建设的风格设置/江北seo页面优化公司
  • 用什么做php网站/设计网站排名
  • 域名和网站绑定/seo综合查询是什么意思
  • 做网站时遇到的问题/优帮云排名优化
  • 广州市网站建设科技/网推团队
  • 专做奢侈品的网站/安卓优化大师老版本
  • tk网站域名注册/百度学术论文查重免费
  • 北京营销网站建设/百度seo排名培训 优化