oracle:

当前时间:sysdate
– dual (Oracle中的一张内部表,只有一行一列,一般用作特定查询)

时间转字符串: to_char(date,format)

 select to_char(sysdate,'yyyy"年"mm"月"dd"日"') 时间转字符串 from dual;

2019年04月18日

字符串转时间: to_date(str,format)

select to_date('2018-02-23 15:33:21','yyyy-mm-dd hh24:mi:ss') 字符串转时间 from dual;

2018-02-23 15:33:21
两个参数的格式必须匹配

mysql:
当前时间:now()

时间转字符串: date_format(date,’%Y-%m-%d’)

  select date_format(now(), '%Y-%m-%d %H:%i:%s');

2019-04-18 15:39:16

字符串转时间: str_to_date(date,’%Y-%m-%d’)

  select str_to_date('2016-09-09 15:43:28', '%Y-%m-%d %H:%i:%s');

2016-09-09 15:43:28
%Y:4位的年份
%y:代表2为的年份
%m:代表月, 格式为(01……12)
%c:代表月, 格式为(1……12)
%d:代表月份中的天数,格式为(00……31)
%e:代表月份中的天数, 格式为(0……31)
%H:代表小时,格式为(00……23)
%k:代表 小时,格式为(0……23)
%h: 代表小时,格式为(01……12)
%I: 代表小时,格式为(01……12)
%l :代表小时,格式为(1……12)
%i: 代表分钟, 格式为(00……59)
%r:代表 时间,格式为12 小时(hh:mm:ss [AP]M)
%T:代表 时间,格式为24 小时(hh:mm:ss)
%S:代表 秒,格式为(00……59)
%s:代表 秒,格式为(00……59)

sqlserver:
当前时间:getdate()

convert(目标类型[datatime/varchar],'输入内容'[时间/字符串],格式);

时间转字符串:

select convert(varchar(100), GETDATE(), 101)
04/06/2019

select convert(varchar(100), GETDATE(), 11)
19/04/06
select convert(varchar(100), GETDATE(), 12)
190406
select convert(varchar(100), GETDATE(), 23)
2019-04-06
select convert(varchar(100), GETDATE(), 24)
16:44:26
select convert(varchar(100), GETDATE(), 102)
2019.04.06
select convert(varchar(100), GETDATE(), 111)
2019/04/06
select convert(varchar(100), GETDATE(), 112)
20190406
select convert(varchar(100), GETDATE(), 120)
2019-04-06 16:48:02
select convert(varchar(100), GETDATE(), 121)
2019-04-06 16:48:12.267

字符串转时间:

select convert(datetime,‘11/1/2003’,101)
2003-11-01 00:00:00.000

select convert(date,‘11/1/2003’)
2003-11-01

postgresql:

当前时间:now(),current_timestamp

时间转字符串:

select to_char(now(), 'yyyy-mm-dd hh24:mi:ss.us')

2019-04-06 17:17:09.177039

字符串转时间:

select to_date('2018-03-12 18:47:35','yyyy-MM-dd hh24:mi:ss')

2018-03-12

select to_timestamp('2018-03-12 18:47:35','yyyy-MM-dd hh24:mi:ss')

2018-03-12 18:47:35+08

cast用法:

cast(字段名 as 转换的类型 )

select cast(sysdate as timestamp) from dual

select cast(now() as date)

select cast(getdate() as varchar(100))

select cast(123 as decimal(10,2))
–得出decimal型123.00.这里10表示显示数字总个数,2表示小数点后个数

字符串和时间转换sql相关推荐

  1. Linux指令日期转为字符串,linux时间转换函数【转】

    Linux下的时间函数 我们在编程中可能会经常用到时间,比如取得系统的时间(获取系统的年.月.日.时.分.秒,星期等),或者是隔一段时间去做某事,那么我们就用到一些时间函数. linux下存储时间常见 ...

  2. python 字符串和时间转换

    ''' * datestr转换成secs * 将时间字符串转化为秒("2012-07-20 00:00:00"->1342713600.0) * @param datestr ...

  3. java 时间转换字符串_java时间转换字符串万能操作工具类,让你轻松转换

    package util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util. ...

  4. java字符串转时间_java字符串和时间转换

    import java.text.SimpleDateFormat; import java.util.Date; //将long字符串转换成格式时间输出 public class LongToStr ...

  5. C语言实现字符串格式时间转换时间戳

     1.函数实现 #include <string.h> #include <stdio.h> #include <time.h>/* 判断是否闰年 */ #defi ...

  6. momentJs 字符串日期时间转换成date

    由于要给elementui 赋值date类型 百度了好几个答案都是错误 就在官网找了下直接toDate()就可以了 时间类型 2021-08-01 14:06:26 let sja = moment( ...

  7. SQL数据库字符串与时间相互转换

    SQL数据库字符串与时间转换 当前时间:now() 时间转字符串: date_format(date,'%Y-%m-%d') select date_format(now(), '%Y-%m-%d % ...

  8. python时间戳转换成时间_Python 时间戳/字符串/时间 转换

    概要 平时对于时间的处理经常使用python的time和datetime模块,但是用来多次还是对其中的时间戳,字符串和时间转换应用的不太熟练,时间长了不使用就理不清楚,为此整理成文. 视图 时间戳,时 ...

  9. Go 学习笔记(48)— Go 标准库之 time (获取时/分/秒的单位值、标准时间和Unix时间转换、字符串时间和Time类型转换、时区转换、时间的加减/休眠)

    1. 概要说明 import "time" time 包提供了时间的显示和测量用的函数.日历的计算采用的是公历. Go 提供以下几种时间类型: 时间点 Time 时间段 Durat ...

最新文章

  1. 第三讲 一阶线性ODE
  2. 自定义log4j2配置文件地址
  3. IPFS: NAT traversal(NAT穿越)
  4. react 动态路 嵌套动子路由_2020年,我是如何从一名Vueer转岗到React阵营
  5. arcgis导入excel数据_ArcGIS批量导入数据
  6. python函数执行shell_6方法,python中执行shell命令
  7. SpringCloud学习笔记018---SpringBoot前后端分离_集成_SpringSecurity_简单实现
  8. 第二阶段第八天站立会议
  9. Apache Dubbo集群容错
  10. matlab多折线图,MATLAB画出堆叠折线图
  11. Nginx 场景应用
  12. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_9 typeAliases标签和package标签
  13. 转:WaitForSingleObject()函数、WaitForMultipleObject()函数
  14. 如何去除暴风影音2009的广告
  15. Groovy 教程系列(一)-- Groovy 入门
  16. RouterOS(ROS)软路由端口映射转发回流
  17. scrapy爬取京东所有图书
  18. 华为路由器交换机配置命令
  19. pytest单元测试
  20. win10打开蓝牙,蓝牙开关消失,蓝牙和其他设备设置,蓝牙开关不见了

热门文章

  1. 多测师_Python(re 模块)
  2. 如何安装Ubuntu 20.04 LTS服务器的图文教程
  3. Spring Boot DAY03 配置文件的注入
  4. 当编辑内容改变是后 选中内容 Range 的startOffset会被重置
  5. 现代电子计算机音乐制作,现代电子音乐制作利器——Alesis VI61 MIDI键盘
  6. 计算机硬件培训ttp,通信新技术优秀教学平台(TTP).doc
  7. Action Recognition Using Attention-Joints Graph Convolutional Neural Networks翻译
  8. Python安装wheel文件
  9. Latex中如何使用中文?
  10. uni-app前端开发(一)登录功能