kahpeng
03-21-2006, 11:01 AM
Actually, i have found the solution to the formatting of date and time i needed but i have to get date from input and then format the date submitted in the form to the desired output.
HTML codes - Interface
<html>
<head><title>Date Formatting Application</title></head>
<body>
<form name="frmDate" method="post" action="Date.asp">
<h3>Enter a date: </h3><p><input type="text" name="Date">
<p><h3>Select format string (Choices: 1 for mm/dd/yyyy     2 for dd/mm/yyy     3 for /dd/mm/yy):</h3>
<p>
<select name="Choice">
<option value="none" selected>
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<p><h3>Click any date format string:<br>
<input type="radio" name="DateFormat" value="0">General Date (mm/dd/yyyy hh:mm:ss AM/PM)</input><br>
<input type="radio" name="DateFormat" value="2">Short Date (dd/mm/yy)</input><br>
<input type="radio" name="DateFormat" value="1">Long Date (day of week, month Name day, year)</input><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Sample interface for the form can be available at here (http://cc.1asphost.com/kahpeng/sample.html).
Date.asp
<%
dim todaysDate
todaysDate=now()
Function Choice1(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
strYYYY = CStr(DatePart("yyyy", DateValue))
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
Choice1 = strMM & "/" & strDD & "/" & strYYYY
End Function
Function Choice2(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
strYYYY = CStr(DatePart("yyyy", DateValue))
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
Choice2 = strDD & "/" & strMM & "/" & strYYYY
End Function
Function Choice3(DateValue)
Dim strYY
Dim strMM
Dim strDD
strYY = CStr(DatePart("yyyy", DateValue))
If Len(strYY) = 4 Then strYY = right(strYY,2)
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
Choice3 = strDD & "/" & strMM & "/" & strYY
End Function
Response.write ("<u><Strong>Drop Down Choices</strong></u><br>")
Response.write ("Choice 1 : ")
Response.Write Choice1(todaysDate) & (" [mm/dd/yyyy]<br>")
Response.write ("Choice 2 : ")
Response.Write Choice2(todaysDate) & (" [dd/mm/yyyy]<br>")
Response.write ("Choice 3 : ")
Response.Write Choice3(todaysDate) & (" [dd/mm/yy]<br>")
Response.write ("<br>")
Response.write ("<u><Strong>Radio Box Choices</strong></u><br>")
Response.write ("Format 0 : ")
Response.write FormatDateTime(todaysDate,0) & (" [General Date]<br>")
Response.write ("Format 1 : ")
Response.write FormatDateTime(todaysDate,1) & (" [Long Date]<br>")
Response.write ("Format 2 : ")
Response.write FormatDateTime(todaysDate,2) & (" [Short Date]<br>")
%>
Sample of Date.asp can be viewed at here (http://cc.1asphost.com/kahpeng/sample.asp). For this asp document, when i try for currrent date function Now(), there's no problem showing the formatted date but when i need to change to get from input box, i just having problems.
Partly of the questions
A program code required to response error message text for non-date entry in Date text box as
Error msg: You must enter a date.
Is there any way or how can i set a format input so that visitor enter only date in the text box ? How to do the checking ? If non-date input, it should be able to display error message.
I hope there's someone out there which is good in ASP coding skills able to help me, I'm looking forward to solve this problem. God bless me...Thx for any help in advance.
HTML codes - Interface
<html>
<head><title>Date Formatting Application</title></head>
<body>
<form name="frmDate" method="post" action="Date.asp">
<h3>Enter a date: </h3><p><input type="text" name="Date">
<p><h3>Select format string (Choices: 1 for mm/dd/yyyy     2 for dd/mm/yyy     3 for /dd/mm/yy):</h3>
<p>
<select name="Choice">
<option value="none" selected>
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<p><h3>Click any date format string:<br>
<input type="radio" name="DateFormat" value="0">General Date (mm/dd/yyyy hh:mm:ss AM/PM)</input><br>
<input type="radio" name="DateFormat" value="2">Short Date (dd/mm/yy)</input><br>
<input type="radio" name="DateFormat" value="1">Long Date (day of week, month Name day, year)</input><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Sample interface for the form can be available at here (http://cc.1asphost.com/kahpeng/sample.html).
Date.asp
<%
dim todaysDate
todaysDate=now()
Function Choice1(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
strYYYY = CStr(DatePart("yyyy", DateValue))
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
Choice1 = strMM & "/" & strDD & "/" & strYYYY
End Function
Function Choice2(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
strYYYY = CStr(DatePart("yyyy", DateValue))
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
Choice2 = strDD & "/" & strMM & "/" & strYYYY
End Function
Function Choice3(DateValue)
Dim strYY
Dim strMM
Dim strDD
strYY = CStr(DatePart("yyyy", DateValue))
If Len(strYY) = 4 Then strYY = right(strYY,2)
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
Choice3 = strDD & "/" & strMM & "/" & strYY
End Function
Response.write ("<u><Strong>Drop Down Choices</strong></u><br>")
Response.write ("Choice 1 : ")
Response.Write Choice1(todaysDate) & (" [mm/dd/yyyy]<br>")
Response.write ("Choice 2 : ")
Response.Write Choice2(todaysDate) & (" [dd/mm/yyyy]<br>")
Response.write ("Choice 3 : ")
Response.Write Choice3(todaysDate) & (" [dd/mm/yy]<br>")
Response.write ("<br>")
Response.write ("<u><Strong>Radio Box Choices</strong></u><br>")
Response.write ("Format 0 : ")
Response.write FormatDateTime(todaysDate,0) & (" [General Date]<br>")
Response.write ("Format 1 : ")
Response.write FormatDateTime(todaysDate,1) & (" [Long Date]<br>")
Response.write ("Format 2 : ")
Response.write FormatDateTime(todaysDate,2) & (" [Short Date]<br>")
%>
Sample of Date.asp can be viewed at here (http://cc.1asphost.com/kahpeng/sample.asp). For this asp document, when i try for currrent date function Now(), there's no problem showing the formatted date but when i need to change to get from input box, i just having problems.
Partly of the questions
A program code required to response error message text for non-date entry in Date text box as
Error msg: You must enter a date.
Is there any way or how can i set a format input so that visitor enter only date in the text box ? How to do the checking ? If non-date input, it should be able to display error message.
I hope there's someone out there which is good in ASP coding skills able to help me, I'm looking forward to solve this problem. God bless me...Thx for any help in advance.