Discussion Locked

MS Access or SQL

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I'm importing data from a large txt document(that I did not create). This person has each "date" field w/ the time of day as well. (example [2/12/2001 10:58]). How can I have it display just the date. I need it to run queries. prefer sql expression.

10 replies

by burlynerd

In SQL Server, we use CONVERT to trim down to the date. CAST should also work fine.

Assuming that MYDATE is a datetime, try this:

CONVERT(DATETIME,CONVERT(CHAR(11), MYDATE))

Regards,

BN

by shyl

If you've already imported the date time data into the target db to a table and just want to view that data with the time part suppressed you can try the following query in SQL Server

SELECT CONVERT (date_time, ColumnName, 101) AS NewColName fromTableName

Where
ColumnName - Name of the datetime column in question
TableName - Name of the table which holds that field
NewColName - some title to display when showing the query result.

Specifying the style as 101 would display the datefield in mm/dd/yyyy format, the style number can be changed based upon your requirement.

If you want to do in MS Access you can use the FORMAT statement with either Short Date or Medium Date setting specified.

by donq

If you imported into Access set the column Data Type to Date/Time and the Format to Short Date(). Access stores Date/Time as a "double" so you may first need to convert the "mm/dd/yyyy" or "dd/mm/yyyy" text to a date? Check incoming properies to see after importing.

by donq

convert evertthing to the left of the first blank space just in case text is just as you wrote in your sample and your result will automatically Format to Short Date by default!

by jbutcher

The fastest way is to change the field type to text and change the length to 11. This will remove everything to the right of the year. You can then change it back to date format or leave it as a test field.

This discussion is closed to new replies.