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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,708 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K 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