Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting date part alone from a datetime field 1

Status
Not open for further replies.

rchandr3

Programmer
Jun 16, 2003
244
0
0
US
How to do the same? I need that for comparing two fields which differ by time, which we dont mind. Only if the dates are different, we need to take care. We are using Sybase with Crystal Reports

Thanks in advance

 
I converted the date to varchar and solved it myself! Thanks for anyone who made a try!
 
If the comparison you are performing is in Crystal Reports, then you can use the Crystal Reports Date function:
Date( {datetime expression} ).

If you are trying to do this in ASA, ASA has a similar Date function.

ASE may also support a similar function but I don't know for sure as I haven't used it enough to remember.

Either of these methods are probably more efficient than converting to varchar because it allows for a numeric comparison rather than a string comparison.

If your logic is being used in a WHERE clause, and you want it to take advantage of indexing, you'll need to use a compound logical expression. The following example would be capable of using an index on MyTimestamp1 if it existed:

WHERE
MyTimestamp1 >= Date(MyTimestamp2)
and
MyTimestamp1 < Date(MyTimestamp2 + 1)


 
This at least standardizes all datetimes in your column to having the exact timestamps. Then you can easily filter a Cognos report that prompts the user for a date.

convert( datetime, convert( varchar(10), getdate(), 101 ) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top