I want to know the difference in month between 2004-04-16
and 2004-09-30. Im using the datadiff function as
datediff(mm,2004-04-16 ,2004-09-30). The result is 5
month which is correct, but I want to get the remainder
of the days as well. Something like 5.5 days. How can I
get this result?
TIA,
VicRemainder can be difficult...how exaclty do you determine it?
Hopefully this will get you started:
DECLARE @.first varchar(8), @.second varchar(8)
SELECT @.first =3D '20040416'
SELECT @.second =3D '20040930'
SELECT DATEDIFF(mm,@.first ,@.second) AS DateDiff_Months
SELECT DATEDIFF(dd,@.first ,@.second) AS DateDiff_TotalDays
SELECT DATEDIFF(mm,@.first ,@.second) * 30 AS =
AverageAmountOfDaysInMonthDiff
SELECT DATEDIFF(dd,@.first ,@.second) - (datediff(mm,@.first ,@.second) * =
30) AS Remainder
SELECT DATEPART(dd, @.second) - DATEPART(dd, @.first) AS AnotherRemainder
--=20
Keith
"Vic" <vduran@.specpro-inc.com> wrote in message =
news:1398001c44402$349e4ef0$a501280a@.phx
.gbl...
> I want to know the difference in month between 2004-04-16=20
> and 2004-09-30. Im using the datadiff function as=20
> datediff(mm,2004-04-16 ,2004-09-30). The result is 5=20
> month which is correct, but I want to get the remainder=20
> of the days as well. Something like 5.5 days. How can I=20
> get this result?
>=20
> TIA,
> Vic
>|||One other thing to note is that DATEDIFF looks at how many 'boundaries' exis
t between the two dates that you are comparing. So, if you executed DATEDIF
F(month, '2004-04-30', '2004-05-02'), the result would be 1, even though the
re is obviously less than o
ne month in elapsed time between these two dates.
Showing posts with label asdatediff. Show all posts
Showing posts with label asdatediff. Show all posts
Sunday, February 19, 2012
DateDiff question
Labels:
2004-04-16,
2004-04-16and,
2004-09-30,
asdatediff,
database,
datadiff,
datediff,
function,
microsoft,
mysql,
oracle,
server,
sql
DateDiff question
I want to know the difference in month between 2004-04-16
and 2004-09-30. Im using the datadiff function as
datediff(mm,2004-04-16 ,2004-09-30). The result is 5
month which is correct, but I want to get the remainder
of the days as well. Something like 5.5 days. How can I
get this result?
TIA,
Vic
Remainder can be difficult...how exaclty do you determine it?
Hopefully this will get you started:
DECLARE @.first varchar(8), @.second varchar(8)
SELECT @.first =3D '20040416'
SELECT @.second =3D '20040930'
SELECT DATEDIFF(mm,@.first ,@.second) AS DateDiff_Months
SELECT DATEDIFF(dd,@.first ,@.second) AS DateDiff_TotalDays
SELECT DATEDIFF(mm,@.first ,@.second) * 30 AS =
AverageAmountOfDaysInMonthDiff
SELECT DATEDIFF(dd,@.first ,@.second) - (datediff(mm,@.first ,@.second) * =
30) AS Remainder
SELECT DATEPART(dd, @.second) - DATEPART(dd, @.first) AS AnotherRemainder
--=20
Keith
"Vic" <vduran@.specpro-inc.com> wrote in message =
news:1398001c44402$349e4ef0$a501280a@.phx.gbl...
> I want to know the difference in month between 2004-04-16=20
> and 2004-09-30. Im using the datadiff function as=20
> datediff(mm,2004-04-16 ,2004-09-30). The result is 5=20
> month which is correct, but I want to get the remainder=20
> of the days as well. Something like 5.5 days. How can I=20
> get this result?
>=20
> TIA,
> Vic
>
|||One other thing to note is that DATEDIFF looks at how many 'boundaries' exist between the two dates that you are comparing. So, if you executed DATEDIFF(month, '2004-04-30', '2004-05-02'), the result would be 1, even though there is obviously less than o
ne month in elapsed time between these two dates.
and 2004-09-30. Im using the datadiff function as
datediff(mm,2004-04-16 ,2004-09-30). The result is 5
month which is correct, but I want to get the remainder
of the days as well. Something like 5.5 days. How can I
get this result?
TIA,
Vic
Remainder can be difficult...how exaclty do you determine it?
Hopefully this will get you started:
DECLARE @.first varchar(8), @.second varchar(8)
SELECT @.first =3D '20040416'
SELECT @.second =3D '20040930'
SELECT DATEDIFF(mm,@.first ,@.second) AS DateDiff_Months
SELECT DATEDIFF(dd,@.first ,@.second) AS DateDiff_TotalDays
SELECT DATEDIFF(mm,@.first ,@.second) * 30 AS =
AverageAmountOfDaysInMonthDiff
SELECT DATEDIFF(dd,@.first ,@.second) - (datediff(mm,@.first ,@.second) * =
30) AS Remainder
SELECT DATEPART(dd, @.second) - DATEPART(dd, @.first) AS AnotherRemainder
--=20
Keith
"Vic" <vduran@.specpro-inc.com> wrote in message =
news:1398001c44402$349e4ef0$a501280a@.phx.gbl...
> I want to know the difference in month between 2004-04-16=20
> and 2004-09-30. Im using the datadiff function as=20
> datediff(mm,2004-04-16 ,2004-09-30). The result is 5=20
> month which is correct, but I want to get the remainder=20
> of the days as well. Something like 5.5 days. How can I=20
> get this result?
>=20
> TIA,
> Vic
>
|||One other thing to note is that DATEDIFF looks at how many 'boundaries' exist between the two dates that you are comparing. So, if you executed DATEDIFF(month, '2004-04-30', '2004-05-02'), the result would be 1, even though there is obviously less than o
ne month in elapsed time between these two dates.
Labels:
2004-04-16,
2004-04-16and,
2004-09-30,
asdatediff,
database,
datadiff,
datediff,
function,
microsoft,
mysql,
oracle,
server,
sql
Subscribe to:
Posts (Atom)