Home > Database > Mysql Tutorial > How to Convert an Integer to HH:MM:SS::00 Time Format in SQL Server 2008?

How to Convert an Integer to HH:MM:SS::00 Time Format in SQL Server 2008?

Linda Hamilton
Release: 2025-01-01 04:17:10
Original
484 people have browsed it

How to Convert an Integer to HH:MM:SS::00 Time Format in SQL Server 2008?

Converting Integer Time to HH:MM:SS::00 Format in SQL Server 2008

To convert an integer representation of time to the HH:MM:SS::00 format in SQL Server 2008, follow these steps:

  • Extract Hour: Divide the integer value by 1000000 and take the remainder modulo 100. This result represents the hour.
  • Extract Minute: Divide the previous result by 10000 and take the remainder modulo 100. This result represents the minute.
  • Extract Second: Divide the previous result by 100 and take the remainder modulo 100. This result represents the second.
  • Extract Millisecond: Multiply the remainder by 10. This result represents the millisecond.

Example:

To convert the integer 23421155 to time format, use the following query:

DECLARE @T INT = 23421155;

SELECT (@T / 1000000) % 100 AS Hour,
       (@T / 10000) % 100 AS Minute,
       (@T / 100) % 100 AS Second,
       (@T % 100) * 10 AS Millisecond;
Copy after login

Result:

Hour Minute Second Millisecond
23 42 11 55

Clarification:

In the HH:MM:SS::00 format, the double colon (::) represents the decimal point. The digits following the decimal point represent the milliseconds.

The above is the detailed content of How to Convert an Integer to HH:MM:SS::00 Time Format in SQL Server 2008?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template