troubleshooting Question

SP converting date time to date and time separately

Avatar of Aleks
AleksFlag for United States of America asked on
Web DevelopmentASPSQL
2 Comments1 Solution172 ViewsLast Modified:
I have a SP that will compare a datetime field with today's date
I also want to extract the time only for a separate column

I tried the following:


The first one will return todays date with zeros in the time part of the field (2017-04-18 00:00:00.000)

In order to compare to my "date_start"  field which contains time, I need to 'remove' the time portion or make it all zeros.
I tried using the

    DECLARE @datetime_start_today [DATETIME] = CONVERT([DATETIME], CONVERT([DATE], datetime_start));

I get an error saying 'datetimestart'  field does not exist, when in fact it does.

Once that is fixed (I assume my syntax is incorrect). I need to compare both dates

WHERE @datetime_start_today = @today

The above should compare only the dates and not the times.

Finally I also want to extract the time only so it shows on the screen as "10:00 AM"  for example

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros