Number of Calendar days between 2 dates
I'm using the datediff(d,starttime,endtime) function but whenever the number
of days is less than 24 hours, I get '-1' as a result instead of 0 like I
want, how can I accomplish this please
Calculate the number of days between two dates that will count anything less
than 24 hours as '0' instead of '-1'
# 1 Re: Number of Calendar days between 2 dates
I think you are using SQL Server (if memory servers). Are you doing this
in SQL or a Stored Proc? If so I'm pretty sure there is a T-SQL function
that functions like the VB IIf function.
"sheryl kemp" <dianedinero@aol.com> wrote:
>
>
>I'm using the datediff(d,starttime,endtime) function but whenever the number
>of days is less than 24 hours, I get '-1' as a result instead of 0 like
I
>want, how can I accomplish this please
>
>Calculate the number of days between two dates that will count anything
less
>than 24 hours as '0' instead of '-1'
MarkN at 2007-11-11 23:52:32 >

# 2 Re: Number of Calendar days between 2 dates
sheryl,
You've simply got your dates reversed. As a general rule, the greater date
is the 2nd argument.
Having said that, if what you're interested in is the absolute difference,
SQL Server is telling you that there is a 1 day difference, it's just that
your first argument was greater than the second, hence it's negative. Wrap
the DATEDIFF( ) call in ABS( ) to get the absolute value.
Ex: SELECT DATEDIFF(day, '10/23/2002 04:30:00', '10/22/2002 23:45:00')
returns -1
But: SELECT ABS(DATEDIFF(day, '10/23/2002 04:30:00', '10/22/2002 23:45:00'))
returns 1.
James Hokes
"sheryl kemp" <dianedinero@aol.com> wrote in message
news:3db41b9f$1@tnews.web.dev-archive.com...
>
>
> I'm using the datediff(d,starttime,endtime) function but whenever the
number
> of days is less than 24 hours, I get '-1' as a result instead of 0 like I
> want, how can I accomplish this please
>
> Calculate the number of days between two dates that will count anything
less
> than 24 hours as '0' instead of '-1'