When I look at the output of it I see it is getting converted to 2018-01-31 00:00:00.000

I can't reproduce your result. select convert(datetime,'1/1/2018') doesn't return Jan 31st. It returns Jan 1st.

I am using this to fetch data based on the converted date and it fails to retrieve this record 1/1/2018 15:10:43 because of the time thing

Since you are converting it to a DATETIME, it gets a time of 00:00:00 which is midnight. Thus, it fails to retrieve anything after midnight, like 15:10 on the same day. The easiest thing is to make your operator < the next day... so you don't have to account for hours, minutes, seconds, milliseconds...

where fetch < '20180102'

Notice I didn't use convert since SQL Server will handle that for us, but feel free to add it if it makes it clearer for you.

where fetch < convert(datetime,'20180102')

Also note that I used ANSI standars of YYYYMMDD. Other methods, which will cause issues when you use DATETIME2 or want a more precise measurement, is to add seconds to your date and use <=.

select dateadd(second,86399,convert(datetime,'20180101'))

Notice this has milliseconds of 000 though, so this can creep up on you later which is why I suggest using the next day.

For milliseconds...

select dateadd(millisecond,86399999,convert(datetime2,'20180101'))
Answer from S3S on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › cast-and-convert-transact-sql
CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn
SQL Server provides the two digit year cutoff configuration option to change the cutoff year used by SQL Server. This allows for the consistent treatment of dates. We recommend specifying four-digit years. 3 Input when you convert to datetime; output when you convert to character data.
🌐
W3Schools
w3schools.com › sql › func_sqlserver_convert.asp
SQL Server CONVERT() Function
SELECT CONVERT(datetime, '2017-08-25'); Try it Yourself » · Convert an expression from one data type to another (varchar): SELECT CONVERT(varchar, '2017-08-25', 101); Try it Yourself » · ❮ Previous ❮ SQL Server Functions Next ❯ · ★ +1 · Sign in to track progress ·
🌐
MSSQLTips
mssqltips.com › home › sql date format examples using convert function
SQL Date Format Examples using SQL CONVERT Function
September 26, 2025 - SQL Server function to convert integer date to datetime format · SQL Database DateTime Best Practices · Format SQL Server Dates with FORMAT Function · SQL Server Date Functions · Add and Subtract Dates using DATEADD in SQL Server · DATEDIFF SQL Server Function ·
🌐
SQL Easy
sql-easy.com › learn › how-to-convert-datetime-to-date-in-sql-server
How to Convert DATETIME to DATE in SQL Server Effortlessly - SQL Knowledge Center
February 9, 2024 - SELECT CONVERT(DATE, datetime_column) FROM table_name; Similar to CAST, CONVERT changes the data type but allows for style formatting, which is particularly useful in specific scenarios or database systems like SQL Server.
🌐
GeeksforGeeks
geeksforgeeks.org › sql › sql-query-to-convert-datetime-to-date
SQL Query to Convert DateTime to Date in SQL Server - GeeksforGeeks
Explanation: Here, the CAST() function is used to convert a string representation of DateTime to a Date, removing the time component. The CONVERT() function is another SQL Server function that allows you to convert data types.
Published   July 23, 2025
Top answer
1 of 2
3

When I look at the output of it I see it is getting converted to 2018-01-31 00:00:00.000

I can't reproduce your result. select convert(datetime,'1/1/2018') doesn't return Jan 31st. It returns Jan 1st.

I am using this to fetch data based on the converted date and it fails to retrieve this record 1/1/2018 15:10:43 because of the time thing

Since you are converting it to a DATETIME, it gets a time of 00:00:00 which is midnight. Thus, it fails to retrieve anything after midnight, like 15:10 on the same day. The easiest thing is to make your operator < the next day... so you don't have to account for hours, minutes, seconds, milliseconds...

where fetch < '20180102'

Notice I didn't use convert since SQL Server will handle that for us, but feel free to add it if it makes it clearer for you.

where fetch < convert(datetime,'20180102')

Also note that I used ANSI standars of YYYYMMDD. Other methods, which will cause issues when you use DATETIME2 or want a more precise measurement, is to add seconds to your date and use <=.

select dateadd(second,86399,convert(datetime,'20180101'))

Notice this has milliseconds of 000 though, so this can creep up on you later which is why I suggest using the next day.

For milliseconds...

select dateadd(millisecond,86399999,convert(datetime2,'20180101'))
2 of 2
0

If you are going to use a converted datetime to compare you need to be aware that it will always receive a time of 00:00:00.000. This will cause anything on that given date but with a greater time to be excluded from your results set.

To solve this issue you need to set the time on the field you are searching on to match. The code below will make every result in your datetime field have a time of 00:00:00.000, the same as your converted date.

(DATEADD(dd, DATEDIFF(dd, 0, my_col)
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › data-types › datetime-transact-sql
datetime (Transact-SQL) - SQL Server | Microsoft Learn
DECLARE @date DATE = '2016-12-21'; DECLARE @datetime DATETIME = @date; SELECT @datetime AS '@datetime', @date AS '@date'; When the conversion is from time(n), the time component is copied, and the date component is set to 1900-01-01.
🌐
DotFactory
dofactory.com › sql › convert-datetime-to-date
SQL Convert DATETIME to DATE
This example converts the current datetime to a date. SELECT CONVERT(DATE, GETDATE()) AS Date Try it live ... GETDATE returns the current database server's datetime.
Find elsewhere
🌐
Database Star
databasestar.com › convert-datetime-to-date
How to Convert DATETIME to DATE in SQL Server | Database Star: Home
July 2, 2020 - The syntax for this is CONVERT (datetime, format). For example, to convert the current date and time into just a date: ... This shows the date only and no time. ... There are different ways you can use CAST, DATEDIFF, FLOOR, and CONVERT to get ...
🌐
SQLines
sqlines.com › sql-server-to-mysql › functions › convert_datetime
SQL Server CONVERT for Datetime in MySQL - SQLines Tools
In SQL Server, you can use CONVERT function to convert a string with the specified format to a DATETIME value. In MySQL, you can use STR_TO_DATE function if you need a specific format, or CONVERT if you need the default format. Note that the order of parameters in SQL Server and MySQL CONVERT ...
🌐
DotFactory
dofactory.com › sql › convert-string-to-datetime
SQL Convert String to DATETIME
SELECT CONVERT(DATETIME, '2022-04-28') AS Datetime Try it live ... If no time is specified, it will be set to 00:00:00.000.
🌐
CodingSight
codingsight.com › home › converting datetime to yyyy-mm-dd format in sql server
How to Convert DateTime to Date Format in SQL Server
July 24, 2023 - We learned to use the CAST function to convert different data types including DateTime and strings to YYYY-MM-DD format and the CONVERT function to turn the YYYY-MM-DD dates to other formats.
🌐
Tutlane
tutlane.com › article › sql-server › convert-format-datetime-in-sql-server-with-examples
Convert (Format) DateTime in SQL Server with Examples - Tutlane
SELECT CONVERT(VARCHAR(30), GETDATE(), 108) ------------------------------------------ 10:12:35 · Like this, we have different format codes available to format the datetime data type value to the required format. The following table lists all the available format codes in SQL Server to convert or format the given datetime value based on our requirements.
🌐
InfluxData
influxdata.com › home › how does date conversion work in sql? | influxdata
How Does Date Conversion Work in SQL? | InfluxData
October 6, 2023 - ... DECLARE @d DATETIME ='2020-12-08 ... at some practical use cases using the functions you just learned about. You can use the FORMAT function to get the day from your date value for a situation like this....
🌐
SQL Shack
sqlshack.com › sql-convert-date-functions-and-formats
SQL Convert Date functions and formats
May 21, 2021 - As highlighted earlier, we might need to format a date in different formats as per our requirements. We can use the SQL CONVERT() function in SQL Server to format DateTime in various formats.
🌐
TechOnTheNet
techonthenet.com › sql_server › functions › convert.php
SQL Server: CONVERT Function
The syntax for the CONVERT function in SQL Server (Transact-SQL) is: CONVERT( type [ (length) ], expression [ , style ] ) ... The datatype that you wish to convert expression to. It can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, ...