Is it possible to get days

# Thread: Is it possible to get days

1. Junior Member
Join Date
Dec 1969
Posts
8

## Is it possible to get days

If i have some 73 days, how can i convert into 2 months and 12 days. Some months are having 30 days and some are having 31 days and Febuary is having 28 days. So how can i determine this. If my days are coming from January, February and March. See here January is having 31 and February is having 28 days. Do i need to specify the Months and days in my program so that it will pick the total from them or what???

2. Senior Member
Join Date
Dec 1969
Posts
96,118

In other words, your question is *impossible* to answer in a general way.<BR><BR>If you had asked "How can I show the number of months and days from 17 January 2003 to 31 March 2003?" then we could give you an answer. But as it is? The answer is "somewhere between 2 months and 11 days and 2 months and 14 days" (if I got my minima and maxima correct).<BR><BR>

3. Junior Member
Join Date
Dec 1969
Posts
8

Thanks for your response. How about getting just number of months and remaining days between two dates Sir..<BR>Here you are getting Years and Months, using this can we get Years, Months AND DAYS..(I found this one here in this forum, by you).. Could you please modify this to get the "DAYS" TOOO... Using &#039;DateDiff&#039;<BR>************************** ****************<BR>mo = DateDiff("m", Date, SvDt) <BR>Right(mo 12,2) & " Years /" & Right(mo MOD 12,2) & " Months." <BR>*******************************************

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## It's more complicated...

...with months. Because there are a different number of days in each month.<BR><BR>Years were simple: there are always 12 months in a year. Hence the MOD 12 is just perfect.<BR><BR>And DATEDIFF isn&#039;t as much help as we could wish: <BR> DATEDIFF( "m", #1/31/2003#, #2/1/2003# )<BR>gives us a difference of one month...even though *ACTUALLY* only ONE DAY has passed!<BR><BR>So this means we have to do adjustments:<BR><BR>&#060;%<BR>Function MonthDayDiff( d1, d2 )<BR> Dim savedt, tempdt, monthCount, dayCount<BR> d1 = CDate( d1 ) &#039; just to be safe<BR> d2 = CDate( d2 ) &#039; ditto<BR> If d1 &#062; d2 Then <BR> tempdt = d1<BR> d1 = d2<BR> d2 = tempdt &#039; swap the order<BR> End If<BR> &#039; prepare for the loop! <BR> savedt = d1<BR> tempdt = DateAdd( "m", 1, savedt )<BR> monthCount = 0<BR> Do While tempdt &#060;= d2<BR> monthCount = monthCount + 1<BR> savedt = tempdt<BR> tempdt = DateAdd( "m", 1, savedt )<BR> Loop<BR> dayCount = DateDiff("d", savedt, d2)<BR> MonthDayDiff = monthCount & " months and " & dayCount & " days"<BR>End Function<BR>%&#062;<BR><BR>I tested it with a few examples. It seems to work. Even on a difficult one such as<BR> MonthDayDiff( #1/31/2003#, #2/28/2004# )<BR>which it reports as 13 months and 0 days. And I think that&#039;s the best answer you can get for those arguments.<BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•