Hello,
I would like to calculate the diferrence between two dates and express the
result as a float of the number of years - such as 3.75 or 5.33333. I am
trying...
CONVERT(float, DATEDIFF(d, MyStartDate, getdate() ) ) /365 as YearsOld
(I realize that dividing by 365 is inaccurate, but it is close enough for my
purposes here)
This line truncates the result to 3.0 or 5.0. What do I need to change in
the syntax?
Thanks in advanceHi Mark,
I get the corretn result when I do this
select CONVERT(float, DATEDIFF(d, convert(datetime,'1 jan 2000'),
getdate() ) ) /365 as YearsOld
but to make sure what you can do is this
select CONVERT(float, DATEDIFF(d, convert(datetime,'1 jan 2000'),
getdate() ) ) / CONVERT(float,365) as YearsOld
kind regards
Greg O
Need to document your databases. Use the firs and still the best AGS SQL
Scribe
http://www.ag-software.com
"Mark Hoffy" <mark@.here.com> wrote in message
news:0nuIe.290$Zo3.52@.fe03.lga...
> Hello,
> I would like to calculate the diferrence between two dates and express the
> result as a float of the number of years - such as 3.75 or 5.33333. I am
> trying...
> CONVERT(float, DATEDIFF(d, MyStartDate, getdate() ) ) /365 as YearsOld
> (I realize that dividing by 365 is inaccurate, but it is close enough for
> my
> purposes here)
> This line truncates the result to 3.0 or 5.0. What do I need to change in
> the syntax?
> Thanks in advance
>
>
Showing posts with label theresult. Show all posts
Showing posts with label theresult. Show all posts
Sunday, February 19, 2012
Tuesday, February 14, 2012
DateDiff
I am using DateDiff format like DATEDIFF(hour,Start,End) and it gave me the
result 12 hours.
Start:- 22 Sep 2006 09:30:00
End:- 22 Sep 2006 21:00:00
Is there any way it will return me 11.5 instead of 12 because it start from
9:30 and end at 21:00 so it must be 11.5 not 12 hours right...
Can any one guid me how I can solve this.
Thanks
No...it wouldn't really be 11.5. The first hour is 9 and the
second hour is 21. The difference between 9 and 21 is 12,
not 11.5. Your asking for the difference based on what
integer value is returned for the hour of the datetime value
you pass in.
Perhaps you want to find the difference in minutes and use
your own logic from there? What do you want to do if it's
9:01 and 21:00?
-Sue
On Wed, 27 Sep 2006 18:37:48 -0400, "Rogers"
<rogers@.hotmail.com> wrote:
>I am using DateDiff format like DATEDIFF(hour,Start,End) and it gave me the
>result 12 hours.
>Start:- 22 Sep 2006 09:30:00
>End:- 22 Sep 2006 21:00:00
>Is there any way it will return me 11.5 instead of 12 because it start from
>9:30 and end at 21:00 so it must be 11.5 not 12 hours right...
>Can any one guid me how I can solve this.
>Thanks
>
|||hi use this way so u will get the correct answer:
datediff(mi, from_time, to_time) / 60.00
ok got it
Rogers wrote:
> I am using DateDiff format like DATEDIFF(hour,Start,End) and it gave me the
> result 12 hours.
> Start:- 22 Sep 2006 09:30:00
> End:- 22 Sep 2006 21:00:00
> Is there any way it will return me 11.5 instead of 12 because it start from
> 9:30 and end at 21:00 so it must be 11.5 not 12 hours right...
> Can any one guid me how I can solve this.
> Thanks
|||Thanks
"samay" <sumi_r2@.rediffmail.com> wrote in message
news:1159408746.872297.16370@.h48g2000cwc.googlegro ups.com...
> hi use this way so u will get the correct answer:
> datediff(mi, from_time, to_time) / 60.00
> ok got it
> Rogers wrote:
>
|||hae it got worked? that date diff?
result 12 hours.
Start:- 22 Sep 2006 09:30:00
End:- 22 Sep 2006 21:00:00
Is there any way it will return me 11.5 instead of 12 because it start from
9:30 and end at 21:00 so it must be 11.5 not 12 hours right...
Can any one guid me how I can solve this.
Thanks
No...it wouldn't really be 11.5. The first hour is 9 and the
second hour is 21. The difference between 9 and 21 is 12,
not 11.5. Your asking for the difference based on what
integer value is returned for the hour of the datetime value
you pass in.
Perhaps you want to find the difference in minutes and use
your own logic from there? What do you want to do if it's
9:01 and 21:00?
-Sue
On Wed, 27 Sep 2006 18:37:48 -0400, "Rogers"
<rogers@.hotmail.com> wrote:
>I am using DateDiff format like DATEDIFF(hour,Start,End) and it gave me the
>result 12 hours.
>Start:- 22 Sep 2006 09:30:00
>End:- 22 Sep 2006 21:00:00
>Is there any way it will return me 11.5 instead of 12 because it start from
>9:30 and end at 21:00 so it must be 11.5 not 12 hours right...
>Can any one guid me how I can solve this.
>Thanks
>
|||hi use this way so u will get the correct answer:
datediff(mi, from_time, to_time) / 60.00
ok got it
Rogers wrote:
> I am using DateDiff format like DATEDIFF(hour,Start,End) and it gave me the
> result 12 hours.
> Start:- 22 Sep 2006 09:30:00
> End:- 22 Sep 2006 21:00:00
> Is there any way it will return me 11.5 instead of 12 because it start from
> 9:30 and end at 21:00 so it must be 11.5 not 12 hours right...
> Can any one guid me how I can solve this.
> Thanks
|||Thanks
"samay" <sumi_r2@.rediffmail.com> wrote in message
news:1159408746.872297.16370@.h48g2000cwc.googlegro ups.com...
> hi use this way so u will get the correct answer:
> datediff(mi, from_time, to_time) / 60.00
> ok got it
> Rogers wrote:
>
|||hae it got worked? that date diff?
Subscribe to:
Posts (Atom)