In SQL Server, there are many different ways to get what you need from the DateTime field.
Here is a list of what we needed for our project.
    This example is based on my son's [date of birth] (Carr Barron). He sadly passed on October 12, 2023, just 4 days before his birthday.
  1. Year = datepart(year, EntryDate) as year
    Copy
    Search Site
    Search Google
    -- Year (1993)
  2. Month = datepart(m, EntryDate) as month
    Copy
    Search Site
    Search Google
    -- Month Number (10)
  3. Month Name = FORMAT(EntryDate,'MMMM') as MonthNam
    Copy
    Search Site
    Search Google
    -- Month Name (October)
  4. Day = datepart(day, EntryDate) as day
    Copy
    Search Site
    Search Google
    -- Day of the the month (16)
  5. Day Name = FORMAT(EntryDate,'dddd') as DayName
    Copy
    Search Site
    Search Google
    - Name of the Day (Saturday)
  6. Hour = datepart(hh, EntryDate) as hour
    Copy
    Search Site
    Search Google
    -- Hour in military Time (14)
  7. Hour = FORMAT(CAST(EntryDate AS DATETIME),'hh') as Standardhour
    Copy
    Search Site
    Search Google
    -- Hour in Standard Time (2)
  8. Minutes = datepart(minute, EntryDate) as minute
    Copy
    Search Site
    Search Google
    -- Minutes
  9. AM/PM = FORMAT(CAST(EntryDate AS DateTime), 'tt') as AMPM
    Copy
    Search Site
    Search Google
    -- Gets the AM or PM (PM)
Here is an example you can run against your database.
(Change the table name from MyTable to your Table name.)
[SQL Server - Get Time from DateTime]
CFFCS | CarrzSynEdit: | SQL Script
SELECT datepart(year, EntryDate) as year, datepart(m, EntryDate) as month, FORMAT(EntryDate,'MMMM') as MonthNam, datepart(day, EntryDate) as day, FORMAT(EntryDate,'dddd') as DayName, datepart(hh, EntryDate) as hour, FORMAT(CAST(EntryDate AS DATETIME),'hh') as Standardhour, datepart(minute, EntryDate) as minute, FORMAT(CAST(EntryDate AS datetime), 'tt') as AMPM

FROM MyTable