Thursday, March 29, 2012

date question

Hi,
I have a date question.
How to translate 365 days to " 1 Year 0 Month 0 Day " or 396 days to " 1
Year 1 Month 1 Day "?
Is any Date Function can do this?
Thanks!
AngiThere is nothing built in that would do this; you would have to write your
own scalar function (this sounds a lot like the common "numbers to words"
problem).
http://www.aspfaq.com/
(Reverse address to reply.)
"angi" <angi@.microsoft.public.sqlserver.olap> wrote in message
news:eLGgtgquEHA.3552@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have a date question.
> How to translate 365 days to " 1 Year 0 Month 0 Day " or 396 days to " 1
> Year 1 Month 1 Day "?
> Is any Date Function can do this?
> Thanks!
> Angi
>|||angi wrote:
> Hi,
> I have a date question.
> How to translate 365 days to " 1 Year 0 Month 0 Day " or 396 days to
> " 1 Year 1 Month 1 Day "?
> Is any Date Function can do this?
> Thanks!
> Angi
You really need to know the exact year in order to do this because you
need to account for leap-years. So you might be better off using a start
and end date, rather than a number of days. You can then run datefiff on
the dates to get the difference in years, months, and days using three
separate calls. See DATEDIFF on BOL.
David Gugick
Imceda Software
www.imceda.com|||That's a good point David.
In which case, a calendar table might be useful.
http://www.aspfaq.com/2519
http://www.aspfaq.com/
(Reverse address to reply.)
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:eqPlXwquEHA.3416@.TK2MSFTNGP09.phx.gbl...
> angi wrote:
> You really need to know the exact year in order to do this because you
> need to account for leap-years. So you might be better off using a start
> and end date, rather than a number of days. You can then run datefiff on
> the dates to get the difference in years, months, and days using three
> separate calls. See DATEDIFF on BOL.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

No comments:

Post a Comment