Solved

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

Posted on 2001-08-29
4
1,143 Views
Last Modified: 2010-05-18
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
Comment
Question by:jeffstatt
  • 2
4 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6436155
where convert(datetime,convert(varchar(13),ExportTimeStamp,113)) = '1 jan 2001'

0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6436170
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
 
LVL 3

Accepted Solution

by:
ibro earned 300 total points
ID: 6436174
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
 

Author Comment

by:jeffstatt
ID: 6436195
That's the one I needed! Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now