Convert integer data type to time

Bob-7209 66 Reputation points
2023-03-27T20:26:53.9766667+00:00

My table lists the date and time fields as integer data types. I need to convert them to normal date formats. I have the date field done. How can I convert the time field with SQL?

User's image

SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2023-03-27T20:41:50.4066667+00:00

    To make a datetime from your two integers, try this expression:

    cast(concat(AppointmentDate, ' ', AppointmentTime / 100, ':', AppointmentTime % 100) as datetime)
    

    If you need just the time:

    timefromparts(AppointmentTime / 100, AppointmentTime % 100, 0, 0, 0)
    

    Use these expressions in SELECT or UPDATE statements.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.