Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1156
  • Last Modified:

Date Conversion in T-SQL -Immediate help needed!!!

This should be an easy question - but I need immediate help...

Here is the logic behind piece of SQL I am trying to run in SQL7

SELECT *
FROM   ExportLog
WHERE  TRUNC(ExportTimeStamp) = '01/01/2001'

Well TRUNC is a command in ORACLE that strips the time part of the argument.  Of course there is no TRUNC command in SQL7.  How do people do this in T-SQL??

is there some kind of TO_DATE or FORMAT function I can use on the date?  i.e:

SELECT *
FROM ExportLog
WHERE Format(ExportTimeStamp, 'yyyymmdd') = '20010101'

Thanks for your help
0
jeffstatt
Asked:
jeffstatt
  • 2
1 Solution
 
nigelrivettCommented:
where convert(datetime,convert(varchar(13),ExportTimeStamp,113)) = '1 jan 2001'

0
 
nigelrivettCommented:
The above does the comparison in a date datatype.
If you wanted to use '20010101' as character then you could

replace(convert(varchar(10),ExportTimeStamp,121),'-','') = '20010101'
0
 
ibroCommented:
SELECT *
FROM ExportLog
WHERE convert(varchar,ExportTimeStamp,101) = '01/01/2001'

101 means date is in format 'mm/dd/yyyy'

see convert help in BOL for more date formats
0
 
jeffstattAuthor Commented:
That's the one I needed! Thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now