I need to figure out how to compare a column that is a varchar and change it to a date, then add in a different column that is also a varchar and convert it to a time (don't ask, bad DB design), and then see if the date is equal to or greater than 24 hours before today's date and current time. Please email me if you need clarification. THANK YOU IN ADVANCE AS THIS IS URGENT AND NEEDED BY TOMORROW EVENING!|||try this, CONVERT (smalldatetime, %26lt;YOUR DATE FIELD%26gt; + %26lt;YOUR TIME FIELD%26gt;) alternatively try casting CAST (%26lt;YOUR DATE FIELD%26gt; + %26lt;YOUR TIME FIELD%26gt;), smalldatetime)...you may have to add a space in between the fields as in %26lt;YOUR DATE FIELD%26gt; + ' ' + %26lt;YOUR TIME FIELD%26gt; hope this helps. To test this you can use DATEDIFF function see:http://msdn.microsoft.com/library/defaul鈥?/a>|||Lets say column1 as date (with format of 'mmddyyyy') and column2 as time portion (with format of hh24:mi:ss').
In Oracle,
select (case
when to_date(column1 || ' ' || column2, 'mmddyyyy hh24:mi:ss') %26gt; sysdate then 'Tomorrow'
when to_date(column1 || ' ' || column2, 'mmddyyyy hh24:mi:ss') %26lt; sysdate then 'Today'
else 'Not a good day') date_check
from tablename;|||this kinda depends on the database you're using.
IF it's mysql, you can convert the string into a timestamp, then extract the date and time out of that, stick them into the two columns, then use timediff to figure out the difference.|||I am a database development programer, you use some tools and learn sql(struct query language ). You can get one tool of Advanced SQL Builder at http://www.dlkj.net/sqlBuilder/ . My email is ymx@hdrj.net. OK?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment