July 15, 2005 at 1:20 pm
Hi,
I searched the forum for this topic but can't find a match.
I have a column(varchar) that records the time of day a particular action occurs. The row is inserted with an sp that runs at a set time daily. The time is currently hardcoded in the sp. Grates my last nerve to do that.
Besides, I want the flexibility to run this throughout the day.
Here's my solution:
case when datepart(hh, getdate()) < 10 then '0' + cast(datepart(hh, getdate()) as varchar)
else cast(datepart(hh, getdate())as varchar) end +
case when datepart(n, getdate()) < 10 then ':0' + cast(datepart(n, getdate()) as varchar)
else ':' + cast(datepart(n, getdate())as varchar) end +
case when datepart(ss, getdate()) < 10 then ':0' + cast(datepart(ss, getdate()) as varchar)
else ':' + cast(datepart(ss, getdate())as varchar) end
Not real pretty but it concatenates all the time segments nicely. Any other ideas on getting a time that doesn't drop the leading zero's in hours(0-24)/minutes/seconds? NOTE: I'm stuck with the varchar datatype for this table.
Thanks,
Greg H
July 15, 2005 at 1:24 pm
select convert(varchar(12),getdate(),114)
* Noel
July 15, 2005 at 1:28 pm
Noel,
I knew there had to be a quicker way. Just couldn't find it.
Thanks,
Greg H
July 15, 2005 at 1:30 pm
Happy to Help
* Noel
July 18, 2005 at 4:19 pm
Surely holding the date/time in a varchar column should also grate ....
James Horsley
Workflow Consulting Limited
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply