forsters
asked on
converting text to datetime
hi experts,
I the following string in a sql select query:
Convert(varchar(12),Deadli neDate,107 )+" "+Convert(varchar(5),Deadl ineTime, 108) Deadline
this is merging a date and time from the two datetime fields to provide a single formatted datetime on a web page.
I am being asked to order on this end datetime (Deadline) which is causing me problems since it is now text. Can I convert the result back to a datetime somehow?
I the following string in a sql select query:
Convert(varchar(12),Deadli
this is merging a date and time from the two datetime fields to provide a single formatted datetime on a web page.
I am being asked to order on this end datetime (Deadline) which is causing me problems since it is now text. Can I convert the result back to a datetime somehow?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
?? maybe just cast the time field to time without date
order by DeadlineDate, cast(DeadlineTime as time)
order by DeadlineDate, cast(DeadlineTime as time)
ASKER
ha, very good yes that would probably do it, i'll have a go later...
ASKER
DATEADD(day, 0, DATEDIFF(day, 0, deadlinedate)) + DATEADD(day, 0 - DATEDIFF(day, 0, deadlinetime), deadlinetime).
many thanks for your reply I had also tried to resolve in the way you suggest but deadlinetime is actually storing a date ( even though it isn't required) and that date was throwing the ordering out on occasions where it conflicted with the deadlinedate.
I will give points regardless - apreciated