sybase datediff mysql_Sybase中的日期时间函数_龙的天空
今天做php项目的时候碰到一个问题,经过上网查找,找到了解决方法,特意记下来,以备以后查找。问题是保存在sybase数据库中的时间格式是类似"2007-06-18 14:12:30"这种格式的,但是当用php从数据库中取出时,格式变了,不是我想要的那种格式。于是上网查了一下sybase的日期时间函数,找到了sybase中常用的日期时间函数如下:
日期函数
getdate()
得到当前时间,可以设置得到各种时间格式.
datepart(日期部分,日期)
取指定时间的某一个部分,年月天时分秒.
datediff(日期部分,日期1,日期2)
计算指定的日期1和日期2的时间差多少.
dateadd(日期部分,数值表达式,日期)
计算指定时间,再加上表达式指定的时间长度.
--取时间的某一个部分
select datepart(yy,getdate()) --year
select datepart(mm,getdate()) --month
select datepart(dd,getdate()) --day
select datepart(hh,getdate()) --hour
select datepart(mi,getdate()) --min
select datepart(ss,getdate()) --sec
--取星期几
set datefirst 1
select datepart(weekday,getdate()) --weekday
--字符串时间
select getdate() -- ‘03/11/12‘
select convert(char,getdate(),101) -- ‘09/27/2003‘
select convert(char,getdate(),102) -- ‘2003.11.12‘
select convert(char,getdate(),103) -- ‘27/09/2003‘
select convert(char,getdate(),104) -- ‘27.09.2003‘
select convert(char,getdate(),105) -- ‘27-09-2003‘
select convert(char,getdate(),106) -- ‘27 Sep 2003‘
select convert(char,getdate(),107) --‘Sep 27, 2003‘
select convert(char,getdate(),108) --‘11:16:06‘
select convert(char,getdate(),109) --‘Sep 27 2003 11:16:28:746AM‘
select convert(char,getdate(),110) --‘09-27-2003‘
select convert(char,getdate(),111) --‘2003/09/27‘
select convert(char,getdate(),112) --‘20030927‘
select rtrim(convert(char,getdate(),102))+‘ ‘+(convert(char,getdate(),108)) -- ‘2003.11.12 11:03:41‘
--整数时间
select convert(int,convert(char(10),getdate(),112)) -- 20031112
select datepart(hh,getdate())*10000 + datepart(mi,getdate())*100 + datepart(ss,getdate()) -- 110646
--时间格式 "YYYY.MM.DD HH:MI:SS" 转换为 "YYYYMMDDHHMISS"
declare @a datetime,@tmp varchar(20),@tmp1 varchar(20)
select @a=convert(datetime,‘2004.08.03 12:12:12‘)
select @tmp=convert(char(10),@a,112)
select @tmp
select @tmp1=convert(char(10),datepart(hh,@a)*10000 + datepart(mi,@a)*100 + datepart(ss,@a))
select @tmp1
select @tmp=@tmp+@tmp1
select @tmp
--当月最后一天
declare
@tmpstr varchar(10)
@mm int,
@premm int,
@curmmlastday varchar(10)
begin
select @mm=datepart(month,getdate())--当月
select @premm=datepart(month,dateadd(month,-1,getdate())) --上个月
if (@mm>=1 and @mm<=8)
select @tmpstr=convert(char(4),datepart(year,getdate()))+‘.0‘+convert(char(1),datepart(month,dateadd(month,1,getdate())))+‘.‘+‘01‘
else if (@mm>=9 and @mm<=11)
select @tmpstr=convert(char(4),datepart(year,getdate()))+‘.‘+convert(char(2),datepart(month,dateadd(month,1,getdate())))+‘.‘+‘01‘
else
select @tmpstr=convert(char(4),datepart(year,dateadd(year,1,getdate())))+‘.0‘+convert(char(1),datepart(month,dateadd(month,1,getdate())))+‘.‘+‘01‘
select @curmmlastday=convert(char(10),dateadd(day,-1,@tmpstr),102) --当月最后一天
end
我自己组合了一下,利用(convert(char,PUBDATE,102)+‘ ‘+convert(char,PUBDATE,108)) AS PUBDATE先把数据库中PUBDATE字段转换成"2007.06.18 14:12:30"的格式,再利用php的str_replace函数把"."替换成"-",终于得到了我想要的类似"2007-06-18 14:12:30”的日期格式。
sybase datediff mysql_Sybase中的日期时间函数_龙的天空相关推荐
- MySQL中常用日期时间函数及获得
MySQL中常用日期时间函数: 下面的查询选择了所有记录,其date_col的值是在最后30天以内: mysql> SELECT something FROM table WHERE TO_DA ...
- Oracle中的日期时间函数
Oracle中日期时间的处理有时候是非常让人头疼的一件事.下面呢,我将我总结的一些日期时间函数的用法写下来,以作化输出为输入之用. 先来了解些基本概念: 日期时间函数:用于处理DATE和TIMESTA ...
- Mysql 中的日期时间函数汇总
日期和时间函数 MySQL中内置了大量的日期和时间函数,能够灵活.方便地处理日期和时间数据,本节就简单介绍一下MySQL中内置的日期和时间函数. 1 CURDATE()函数 CURDATE()函数用于 ...
- mysql 时间字符串 1_Mysql 中的日期时间字符串查询
一.将数据库中的Date格式的数据,或者指定日期的字符串格式化为想要的样式 DATE_FORMAT (date, format)能根据格式串format 格式化日期或日期和时间值date,返回结果字符 ...
- PHP 中日期时间函数 date() 用法总结
[导读] date()是我们常用的一个日期时间函数,下面我来总结一下关于date()函数的各种形式的用法,有需要学习的朋友可参考.格式化日期date() 函数的第一个参数规定了如何格式化日期 时间.它 ...
- Php中如何记录本报时间,详细讲解PHP的日期时间函数date()
详细讲解PHP的日期时间函数date() 作者:wang 日期:2009-06-06 字体大小: 小 中 大 1,年-月-日 echo date('Y-m-j'); 2007-02-6 echo da ...
- php 中日期时间函数大全,PHP 中日期时间函数 date() 用法总结
[导读] date()是我们常用的一个日期时间函数,下面我来总结一下关于date()函数的各种形式的用法,有需要学习的朋友可参考.格式化日期date() 函数的第一个参数规定了如何格式化日期 时间.它 ...
- MySQL 学习笔记(3)— 字符串函数、数值函数、日期时间函数、流程函数、聚集函数以及分组数据
1. 字符串函数 MySQL 的常用函数包括字符串函数.数值函数.日期时间函数.流程函数等. SELECT ascii("abc"),char(97),concat("h ...
- 转:mysql的日期/时间函数
没事整理下,方便以后查阅 一. Mysql 获得当前日期时间 Now() : 获得当前的 日期+ 时间(date + time )函数: mysql> select now(); +-- ...
最新文章
- 你听过BA、DA、AA、TA么?全网疯传的架构实践全景图!
- 【BZOJ3555】[Ctsc2014]企鹅QQ hash
- C++Wiggle Sort摆动排序的实现算法(附完整源码)
- 洛谷 2921 记忆化搜索 tarjan 基环外向树
- mongodb身份验证_MongoDB身份验证
- 基因治疗光明现,钾盐钠盐大混战;深度学习助力癌早筛,母亲多动降低后代甲基化...
- Scala学习笔记05:函数
- 数据结构:五岔路口交通管理红绿灯设计
- 华为android9升级包,华为Mate9官方固件ROM刷机包
- c 陷阱与缺陷 摘录
- 是潜意识音频优于催眠
- Java每日一题——>739. 每日温度(蛮力法,栈方法)
- ERA5气象数据 :数据中相对湿度、边界层高度、温度、风向、地面气压等参数下载详细教程
- 免费可用的Android手机传感器数据采集程序(附程序)
- 【 第一章:初识 ts】
- 学好水彩,给自己做个手机壳吧
- 计算机硬件系统外设是指,计算机硬件系统.
- bert:pre-training of deep bidirectional transformers for language understanding
- matplotlib作图系列之内置颜色使用(一)
- 怎么将.tex文件转换成pdf