x

How do I change a date field to a numerica field?

I have my ending date field and my beginning date field but need to show the difference as an integer.
more ▼

asked Jun 17, 2011 at 12:08 PM in Default

Maggie62 gravatar image

Maggie62
11 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Difference as an integer representing what? Days? [DATEDIFF function][1] is going to be useful here.

select datediff(dd, '1 jun 2010','30 jun 2010')

Check out the documentation on that link, and change the dd for another datepart to get other values

[1]: http://msdn.microsoft.com/en-us/library/ms189794.aspx
more ▼

answered Jun 17, 2011 at 12:17 PM

Kev Riley gravatar image

Kev Riley ♦♦
52.8k 47 49 76

spot on.Thats the function we need to use.
Jun 17, 2011 at 12:26 PM aRookieBIdev
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x43

asked: Jun 17, 2011 at 12:08 PM

Seen: 614 times

Last Updated: Jun 17, 2011 at 12:08 PM