SQL Server Two time period difference and time intercept to cent

Source: Internet
Author: User

/*--------------------------time to intercept-----------------------------------*/Select  Left(CONVERT(varchar( -),'2017-11-24 19:25:30.740', -), -)--back to 2017-11-24 19:25--separate interceptionSelect DatePart(Hour,'2017-11-24 19:25:30.740')--Return hours/*-----------------Two time periods of difference, accurate to seconds (can be used for countdown)----------------------*/SELECT DATEDIFF(Second,'2009-8-25 12:15:12','2009-9-1 7:18:20')--returns the number of seconds differenceSELECT DATEDIFF(Minute,'2009-9-1 6:15:12','2009-9-1 7:18:20')--return minutes of differenceSELECT DATEDIFF( Day,'2009-8-25 12:15:12','2009-9-1 7:18:20')--returns the difference in number of daysSELECT DATEDIFF(Hour,'2009-8-25 12:15:12','2009-9-1 7:18:20')--returns the difference between hours--The number of minutes to find two time difference--Method OneSELECT CONVERT(INT,DATEDIFF( Day,'2017-11-24 19:00:00','2017-11-24 19:01:00')* -* -)+CONVERT(INT,DATEDIFF(Hour,'2017-11-24 19:00:00','2017-11-24 19:01:00')* -)+CONVERT(INT,DATEDIFF(Minute,'2017-11-24 19:00:00','2017-11-24 19:01:00'))--Method TwoDeclare @day int --daysDeclare @hour int  --hoursDeclare @min int  --pointsDeclare @sec int  --secondsDeclare @alls int  Select GETDATE()Set @alls=DateDiff(S,'2017-11-24 19:00:00',GETDATE())--difference between Time 1 and time 2 (seconds)Set @day=@alls/86400 --daysSet @hour=(@alls-@day*86400)/3600  --hoursSet @min=(@alls-@day*86400-@hour*3600)/ -  --pointsSet @sec=@alls-@day*86400-@hour*3600-@min* -  --secondsSelect CAST(@day  as varchar(5))+'days'+CAST(@hour  as varchar(2))+'hours'+CAST(@min  as varchar(2))+'points'+CAST(@sec  as varchar(2))+'seconds'Cha

SQL Server Two time period difference and time intercept to cent

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.