DATEPART and DATENAME accept a string that holds only a time. They fill in the missing date as January 1, 1900. I ran every query of the quiz on SQL Server 2025. The questions stay as I asked them, and the tested answers follow.

Part 1: Understanding DATENAME
The first part of this quiz is understanding what your functions are. Look at the statements below and guess what the answer would be. Then go ahead and try the same inside SQL Server Management Studio.
-- The reason is there is no “Day” specified in the source datetime. SELECT DATENAME(DAYOFYEAR, '12:12:12.123') [DayOfYear] SELECT DATENAME(WEEKDAY, '12:12:12.123') [WeekDay]
Should the above code work? What is the output, an error or values? If you did get an error, can you spot the reason? If you got values then can you tell why you got those values?
Part 2: Understanding DATEPART
If you got the above correct, then this should be a breeze for sure. You will get the answer easily. Let me know how many got it right just by watching the statements.
-- What about now? SELECT DATEPART(weekday, '12:12:12.123') [WeekDay] SELECT DATEPART(MONTH, '12:12:12.123')[MONTH]
Should the above code work? What is the output, an error or values? If you did get an error, can you spot the reason? If you got values then can you tell why you got those values? Is it different from Part 1 of your guess with DATENAME or same? Can you tell why?
If you got this far, then great. I think you got the basics covered.
Part 3: Bonus Question
I thought it would be interesting to add a twist to the tale and get your guess on what the output should be for the below queries.
-- First SELECT DATENAME(dayofyear, '1') [DayOfYear] -- Second SELECT DATENAME(dayofyear, '1-1') [DayOfYear] -- Third SELECT DATENAME(dayofyear, '2:2') [DayOfYear] -- Fourth SELECT DATENAME(dayofyear, '23:25') [DayOfYear] -- Fifth SELECT DATENAME(dayofyear, '24:25') [DayOfYear]
Now which of the above queries will run without any error?
Let me know via comments to all your guesses and the reasons for those guesses.
The Answer, Tested
I ran each query of the quiz on SQL Server 2025 in its own batch. Parts 1 and 2 return values and no errors.
| Query | Result |
|---|---|
| DATENAME(DAYOFYEAR, ’12:12:12.123′) | 1 |
| DATENAME(WEEKDAY, ’12:12:12.123′) | Monday |
| DATEPART(weekday, ’12:12:12.123′) | 2 |
| DATEPART(MONTH, ’12:12:12.123′) | 1 |
Both functions get a string with a time and no date. SQL Server converts the string to datetime, and a datetime without a date gets the default date. A cast shows it.
SELECT CAST('12:12:12.123' AS datetime) AS AsDatetime, CAST('2:2' AS datetime) AS TwoTwo, CAST('23:25' AS datetime) AS TwentyThree;| AsDatetime | TwoTwo | TwentyThree |
|---|---|---|
| 1900-01-01 12:12:12.123 | 1900-01-01 02:02:00.000 | 1900-01-01 23:25:00.000 |
The default date is January 1, 1900. That day is a Monday, the first day of the year and the first month. So DATENAME returns 1 and Monday, and DATEPART returns month 1. Some readers guessed 1753, the lowest datetime date. The cast shows 1900.
Why DATEPART Says 2
Part 2 asked whether the result differs from Part 1. It does, because DATEPART returns a number and the number depends on a session setting. DATEFIRST sets the first day of the week. On this US English server it is 7, so Sunday is 1 and Monday is 2.
SELECT @@DATEFIRST AS DateFirst, DATEPART(weekday, '12:12:12.123') AS WeekDayNumber; SET DATEFIRST 1; SELECT @@DATEFIRST AS DateFirst, DATEPART(weekday, '12:12:12.123') AS WeekDayNumber; SET DATEFIRST 7;
| DateFirst | WeekDayNumber |
|---|---|
| 7 | 2 |
| 1 | 1 |
With DATEFIRST 1, Monday is day 1. Ritesh M and ijeb explained the 2 in the comments. Monday is the second day when the week starts on Sunday. Both are right for this setting. DATENAME returns the name Monday in both cases. The setting lasts only for the session, and I set it back to 7 at the end.
The Bonus Question, Tested
Only the third and fourth queries run. Each one returns 1. I ran each query in its own batch, because the five do not run together.
| Query | Result |
|---|---|
| DATENAME(dayofyear, ‘1’) | Msg 241 |
| DATENAME(dayofyear, ‘1-1’) | Msg 241 |
| DATENAME(dayofyear, ‘2:2’) | 1 |
| DATENAME(dayofyear, ’23:25′) | 1 |
| DATENAME(dayofyear, ’24:25′) | Msg 241 |
Msg 241, Level 16, State 1, Line 1 Conversion failed when converting date and/or time from character string.
That message is what the Messages tab shows for the three failing queries.
Run as the one block above, the batch stops at the first failing statement. SQL Server returns Msg 241 for line 2 and no rows at all. The third and fourth query never show their 1. In SSMS, select one statement at a time, or put GO between them.
The string ‘2:2′ reads as 02:02 and ’23:25′ as 23:25. Both are valid times, so the default date fills in. The string ’24:25’ fails because hour 24 does not exist. The strings ‘1’ and ‘1-1’ are neither a time nor a full date. Add a year and the date works: DATENAME(dayofyear, ‘1-1-2015’) returns 1 on this server.
MKumar, Pushkar and ijeb named the third and fourth query in the comments, and they were right.
What Changes With a Typed Value
The string literal works only because it is a string. Cast the same text to the time type first, and SQL Server refuses.
SELECT DATENAME(dayofyear, CAST('12:12:12.123' AS time));Msg 9810, Level 16, State 5, Line 1 The datepart dayofyear is not supported by date function datename for data type time.
A time value has no day, so asking it for a day of the year makes no sense. The type tells the truth. The string hides it. Asking the time type for its hour works fine and returns 12.

Is the Default Date a Feature?
You could say the 1900 default is a feature, because the time-only query works. Fair point. It is handy in a demo. In real code it hides a bug: a missing date turns into a Monday in 1900, and no error appears. I would rather get the error.
A Simple Rule
DATEPART and DATENAME are strict about types, so pass typed values, not strings. If the input is a time, keep it as time and ask only for the hour, minute and second. Use DATENAME when you want the weekday name. Use DATEPART(weekday) only when you know the DATEFIRST of the session.
These queries create nothing, so there is nothing to clean up.
A time without a date is not an error, it is January 1, 1900 in disguise.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.





13 Comments. Leave new
Without trying part three, I am guessing all four will return the default of ‘1900-01-01’
out put is 1.converting date and/or time(12:12:12.123)
No guesses !!
for Part 1: Understanding
In the DATENAME function Date parameter expecting a validate date but in the example you are passing value in time format. If date is not in valid then function will use the default date as 01/01/1900 so that is the reason if we run the function it is returning
1 for SELECT DATENAME(DAYOFYEAR, ’12:12:12.123′) [DayOfYear]
Monday for SELECT DATENAME(WEEKDAY, ’12:12:12.123′) [WeekDay]
for Part 2: Understanding DATEPART
Reason is same. in the DATEPART date parameter expect a validate date if we pass any other value other than date then it will assign the default value as 01/01/1900 and on the basis of this we are getting following results
1) first query SELECT DATEPART(weekday, ’12:12:12.123′) [WeekDay] returning 2 because on 01/01/1900 date Weekday is Monday and which is on 2nd Position
2) Second query will return 1 because on the default date we January as first month so returning 1
Part 3: Bonus Question
in simple if we dont pass the validate date and pass the ONLY TIME it will set the default value to 01/01/1900 so for all the query will have date as 01/01/1900 and return the result on the basis of this date.
in the last query set
#1 will not run because 1 is not properly formatted as Date or Time
#2 will not run because 1-1 will not perform any arithematic operation and not have a valid date or time
#3 will run properly and will return 1 because it is first day of Year and date 01/01/1900 is default
#4 will run properly and will return 1 because of first day of year and default date that will club with time is 01/01/1900
#5 will not run because 24:25 is not a valid time.
For Part1&2:
DATENAME() and DATEPART() functions take default date value as 1753-01-01 which is minimum date value for a datetime in SQL Server i.e. SELECT DATENAME(DAYOFYEAR, ‘1753-01-01 12:12:12.123’) [DayOfYear] and executes seccessfully.
For Part3:
only third and fourth query will execute successfully.
SELECT DATENAME(dayofyear, ‘2:2′) [DayOfYear]
output: 1
SELECT DATENAME(dayofyear, ’23:25’) [DayOfYear]
output: 1
With Regards,
Mithun Kumar
Part1 & Part2:
As yyyy:mm:dd value is not supplied in date value, both functions are taking default value as ‘1753-01-01 12:12:12.123’. This date part excluding the time is the minimum date value for a datetime in SQL Server.
Part3:
Only third and fourth query will work and each will give output as 1.
third one
Part 1:
DATENAME ( datepart , date ) : Returns a character string that represents the specified datepart of the specified date.
If the data type of the date argument does not have the specified datepart,
the default for that datepart will be returned only when a literal is specified for date.
For example, the default year-month-day for any date data type is 1900-01-01.
The following statement has date part arguments for datepart,
a time argument for date, and returns 1, Monday.
SELECT DATENAME(dayofyear, ’12:10:30.123′)
,DATENAME(weekday, ’12:10:30.123′);
Part 2:
DATEPART ( datepart , date ) : Returns an integer that represents the specified datepart of the specified date.
If the data type of the date argument does not have the specified datepart,
the default for that datepart will be returned only when a literal is specified for date.
For example, the default year-month-day for any date data type is 1900-01-01.
The following statement has date part arguments for datepart,
a time argument for date, and returns 1, 2.
SELECT DATEPART(month, ’12:10:30.123′)
,DATEPART(weekday, ’12:10:30.123′);
Part 3:
None of the query will run successfully since here is the invalid datepart
For Part1: Got o/p.
Output is based on SQL default date 1 January 1753.
So DAYOFYEAR = 1 and Monday is the day on 1 January 1753.
For Part 2:
[WeekDay] – 2 ( as week starts on Monday)
[MONTH] – 1 ( with default date)
For Part3:
First, Second does not work because, its invalid date format.
— Third
SELECT DATENAME(dayofyear, ‘2:2′) [DayOfYear] — works, valid time with default date
— Fourth
SELECT DATENAME(dayofyear, ’23:25’) [DayOfYear] — works, valid time with default date
Fifth fails, as time in invalid ( more than 24 ?)
Part 1
This runs without error. Result:
1
Monday
De default date January 1, 1900 is used.
This is the first day of the year and a monday.
Part 2
This runs without error. Result:
2
1
De default date January 1, 1900 is used.
Monday is the second day of the week.
January is the first month.
The result is different from part 1 because a different function is called.
Part 3:
Only these two run
SELECT DATENAME(dayofyear, ‘2:2′) [DayOfYear]
SELECT DATENAME(dayofyear, ’23:25’) [DayOfYear]
These are valid time values.
De default date January 1, 1900 is used.
This is the first day of the year
The other queries don’t have valid times or dates.
I recognized right away that they were time formats not date. However I had no Idea what would be considered default nor what would be returned.
However, it gave me something to learn and a place to start.