zoukankan      html  css  js  c++  java
  • 只修改日期不修改时间(巧用convert函数)

         今天又搞了一点新东东上来,嘻嘻,就是时间函数啦,因为我们是做一卡通产品的,485系列的消费机时常会出现时间跳变的情况(其实TCP/IP的机器也会出现,不过概率要小很多),经常会用到一些有关时间的函数对消费日期进行修改。

    用得最多的是:DATEADD (depart,number,date) 在向指定日期加上一段时间的基础上,返回新的 datetime

    讲到DATEADD,当然也同时会想到另外一个时间函数就是DATEDIFF, 返回跨两个指定日期的日期和时间边界数。其格式为: DATEDIFF ( datepart , startdate , enddate )

     

        那我今天用到的不是这两种,呵,是使用了CONVERT函数对日期进行多次转换,达到只修改日期,不修改时间的方法,在此处将SQL陈列如下,希望有需要的朋友可以试用看看.呵~~~~

    update te_creditaccount

    set createdate=convert(datetime,'2009-08-30'+ ' ' +convert(varchar(10),createdate,114))

    where convert(char(10),createdate,21)>'2009-09-05'

    and createoperatorid=2 and termid=0 and cardid in

    (select a.cardid from tc_card a inner join tc_employee b

    on a.employeeid=b.employeeid where convert(char(10),a.createdate,21)>'2009-09-05'

    and a.createoperatorid=2 and b.employeename='临时卡' )

    其实重要的也就是convert(datetime,'2009-08-30'+ ' ' +convert(varchar(10),createdate,114))

    先通过convert()将原日期时间转换为Varchar,并使用114的格式,然后加上需要修改的字段,最后转化为datetime.

    :每天记录一点,每天勤奋一点,为未来做好准备!!!

  • 相关阅读:
    Python学习笔记(四)多进程的使用
    Python学习笔记(三)多线程的使用
    windows无法安装msi文件
    标签传播算法
    信息论基础
    模块度Q
    HTTPS开发(SSL--用Tomcat服务器配置https双向认证)
    oracle 优化
    eclipse 界面开发--windowbuilder
    vba 读取数据库
  • 原文地址:https://www.cnblogs.com/medci/p/1568003.html
Copyright © 2011-2022 走看看