datediff函数用法_sqlserver函数

lingxue 2016-06-03 12:34:26 阅读 656 评论 1 喜欢 0
sqlserver 时间差 函数 sql 函数 时间差 

    datediff()函数 返回两个日期之间的间隔。调用方法如下:

    datediff( date-part, date1, date2 )

        date-part:用于指定比较日期时间的哪个部分

        date1:起始时间

        date2:终止时间

    结果为日期部分中等于(date2 - date1)的有符号的整数值,不可能返回小数值

   date-part 参数可以是下列的值:

datepart缩写
yy, yyyy
季度qq, q
mm, m
年中的日dy, y
dd, d
wk, ww
星期dw, w
小时hh
分钟mi, n
ss, s
毫秒ms
微妙mcs
纳秒ns


    举例: select datediff(hh,'2016-06-3 11:30:00.000','2016-06-3 12:00:00.000')  返回1 (比较小时,忽略分钟)

            select datediff(hh,'2016-06-3 11:59:00.000','2016-06-3 12:00:00.000')  返回1

            select datediff(mi,'2016-06-3 11:30:00.000','2016-06-3 12:00:00.000')   返回30 (比较分钟,忽略秒)

            select datediff(mi,'2016-06-3 11:30:30.000','2016-06-3 12:00:00.000')   返回30

            select datediff(dd,'2016-06-3 11:30:30.000','2016-06-3 12:00:00.000')   返回0 (比较天数,忽略小时)

            select datediff(dd,'2016-06-3 11:30:30.000','2016-06-4 12:00:00.000')   返回1

            select datediff(mm,'2016-06-3 11:30:30.000','2016-07-29 12:00:00.000') 返回 1(比较月份,忽略天)



   


支持@用户名回复

×  

:bowtie: :smile: :laughing: :blush: :smiley: :relaxed: :smirk: :heart_eyes: :kissing_heart: :kissing_closed_eyes: :flushed: :relieved: :satisfied: :grin: :wink: :stuck_out_tongue_winking_eye: :stuck_out_tongue_closed_eyes: :grinning: :kissing: :kissing_smiling_eyes: :stuck_out_tongue: :sleeping: :worried: :frowning: :anguished: :open_mouth: :grimacing: :confused: :hushed: :expressionless: :unamused: :sweat_smile: :sweat: :weary: :pensive: :disappointed: :confounded: :fearful: :cold_sweat: :persevere: :cry: :sob: :joy: :astonished: :scream: :neckbeard: :tired_face: :angry: :rage: :triumph: :sleepy: :yum: :mask: :sunglasses: :dizzy_face: :imp: :smiling_imp: :neutral_face: :no_mouth: :innocent: :alien: :yellow_heart: :blue_heart: :purple_heart: :heart: :green_heart: :broken_heart: :heartbeat: :heartpulse: :two_hearts: :revolving_hearts: :cupid: :sparkling_heart: :sparkles: :star: :star2: :dizzy: :boom: :collision: :anger: :exclamation: :question: :grey_exclamation: :grey_question: :zzz: :dash: :sweat_drops: :notes: :musical_note: :fire: :hankey: :poop: :shit: :+1: :thumbsup: :-1: :thumbsdown: :ok_hand: :punch: :facepunch: :fist: :v: :wave: :hand: :open_hands: :point_up: :point_down: :point_left: :point_right: :raised_hands: :pray: :point_up_2: :clap: :muscle: :metal: :walking: :runner: :running: :couple: :family: :two_men_holding_hands: :two_women_holding_hands: :dancer: :dancers: :ok_woman: :no_good: :information_desk_person: :raised_hand: :bride_with_veil: :person_with_pouting_face: :person_frowning: :bow: :couplekiss: :couple_with_heart: :massage: :haircut: :nail_care: :boy: :girl: :woman: :man: :baby: :older_woman: :older_man: :person_with_blond_hair: :man_with_gua_pi_mao: :man_with_turban: :construction_worker: :cop: :angel: :princess: :smiley_cat: :smile_cat: :heart_eyes_cat: :kissing_cat: :smirk_cat: :scream_cat: :crying_cat_face: :joy_cat: :pouting_cat: :japanese_ogre: :japanese_goblin: :see_no_evil: :hear_no_evil: :speak_no_evil: :guardsman: :skull: :feet: :lips: :kiss: :droplet: :ear: :eyes: :nose: :tongue: :love_letter: :bust_in_silhouette: :busts_in_silhouette: :speech_balloon: :thought_balloon:

共1条评论

  • Buffex : 沙发我的 。
     2016-10-11 16:37:05

相似文章

  • 顶部
  • 关灯
  • 留言
  • 点赞