The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
Hi,
I am trying to write a script that will take a datediff integer and divide it into days weeks, months. I need it to give me the weeks and or days left over.
I am trying to achieve this looping through the number but with no luck. In this case a month has to be 30 days which i think should make it easier than dealing with calendar months.
Thanks in advance.
I am trying to write a script that will take a datediff integer and divide it into days weeks, months. I need it to give me the weeks and or days left over.
I am trying to achieve this looping through the number but with no luck. In this case a month has to be 30 days which i think should make it easier than dealing with calendar months.
Thanks in advance.
Posted
Have you tried asking over at http://stackoverflow.com ? While we do answer the occasional general programming question, we tend to do better with forum related questions... this being the forum's support forum and all.
Posted
That's basic math. If your datediff is 2497, for example:
This results in the following output:
83=Months
1=Weeks
0=Days
Now all you do is populate the intVal with a variable and you're all set.
Code:
<%
intVal=2497
' Obtain the months
intMM=int(intVal/30)
Response.Write intMM&"=Months<br>"
' Obtain remainder
intMML=intVal-(30*intMM)
' Calculate weeks (if any)
if intMML/7 >= 1 then
intWW=int(intMML/7)
Response.Write intWW&"=Weeks<br>"
intDD=intMML-(7*intWW)
Response.Write intDD&"=Days"
else
' Calculate days (if any)
intDD=intMML
Response.Write intDD&"=Days"
end if
%>
This results in the following output:
83=Months
1=Weeks
0=Days
Now all you do is populate the intVal with a variable and you're all set.
Last edited by Carefree on 28 May 2009, 14:33
Posted
I'd just use the datepart function.
http://msdn.microsoft.com/en-us/library/4kt42529(VS.85).aspx
http://msdn.microsoft.com/en-us/library/4kt42529(VS.85).aspx
======
Doug G
======
Computer history and help at www.dougscode.com
Doug G
======
Computer history and help at www.dougscode.com
Posted
The datepart isn't going to use a standard 30 day month.
Here's a version where you can fill in a blank and get your results. Save as "datediff.asp".
Here's a version where you can fill in a blank and get your results. Save as "datediff.asp".
Code:
<%
Response.Write "<form action=""DateDiff.asp"" method=""post"" name=""DateDiff"">" & vbNewLine & _
"<table width=""30%"" align=""center"" bgcolor=""cyan"" borders=""0"" cellpadding=""1"" cellspacing=""3"">" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" bgcolor=""lightcyan"" colspan=""6"">Date Difference" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" bgcolor=""lightgrey"" colspan=""6"">" & vbNewLine & _
" <input style=""text-align: center; text-decoration:blink;"" type=""text"" name=""Val"" size=""5"" maxlength=""5"" value=""" & Request.Form("Val") & """>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" bgcolor=""lightcyan"" width=""(100/6)%"">Months" & vbNewLine & _
" </td>" & vbNewLine
intVal=Request.Form("Val")
intMM=int(intVal/30)
strMM=cStr(intMM)
intMML=intVal-(30*intMM)
if intMML/7 >= 1 then
intWW=int(intMML/7)
strWW=cStr(intWW)
intDD=intMML-(7*intWW)
strDD=cStr(intDD)
if intDD=0 then strDD="0"
else
strWW="0"
intDD=intMML
strDD=cStr(intDD)
if strDD="" then strDD="0"
end if
Response.Write " <td align=""center"" bgcolor=""white"" width=""(100/6)%"">" & strMM & "" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""center"" bgcolor=""lightcyan"" width=""(100/6)%"">Weeks" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""center"" bgcolor=""white"" width=""(100/6)%"">"& strWW & "" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""center"" bgcolor=""lightcyan"" width=""(100/6)%"">Days" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""center"" bgcolor=""white"" width=""(100/6)%"">" & strDD & "" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
"</table>" & vbNewLine & _
"<center><input type=""submit"" value=""Submit"" id=""submit""></center>" & vbNewLine & _
"</form>" & vbNewLine
%>
Last edited by Carefree on 28 May 2009, 15:06
Posted
Thanks so much.
Posted
The datepart isn't going to use a standard 30 day monthMaybe because 30 days isn't standard for a month? And the OP's premise that using 30 day months would be easier isn't correct, you have to do a lot more coding to deal with a non-calendar month interval since all the hard work about dealing with dates has already been done for you when you use the built-in date functions.
======
Doug G
======
Computer history and help at www.dougscode.com
Doug G
======
Computer history and help at www.dougscode.com
Email Member
Message Member
Post Moderation
FileUpload
If you're having problems uploading, try choosing a smaller image.
Preview post
Send Topic
Loading...