Split, convert date question ??

D

David

Hi,

I have a form which is posting a user entered date to an asp page.
The date is then used in a SQL string.

The format of the date is received as dd/mm/yyyy, with the user typing
the '/' as well

how can I convert it to yyyy-mm-dd

----------------

I have tried this, but I think I need to strip out the '/' ??, as it is
not working

D1 = cdate(request.form("date"))

strDay = Day(D1)
strMonth = Month(D1)
strYear = Year(D1)

NewstrDate = strYear & "-" & strMonth & "-" & strDay

Appreciate your help, thanks so much :)
 
M

Mike Brind

David said:
Hi,

I have a form which is posting a user entered date to an asp page.
The date is then used in a SQL string.

The format of the date is received as dd/mm/yyyy, with the user typing
the '/' as well

how can I convert it to yyyy-mm-dd

----------------

I have tried this, but I think I need to strip out the '/' ??, as it is
not working

D1 = cdate(request.form("date"))

strDay = Day(D1)
strMonth = Month(D1)
strYear = Year(D1)

NewstrDate = strYear & "-" & strMonth & "-" & strDay

Appreciate your help, thanks so much :)

You almost had it - you need to use the Split() function:

<%
Function changeUserDate(userDate)
temp = Split(userDate,"/")
strDay = temp(0)
strMonth = temp(1)
strYear = temp(2)
changeUserDate = strYear & "-" & strMonth & "-" & strDay
End Function

Response.Write changeUserDate(Request.Form("date"))
%>

Personally, I use a javascript calendar so that users can select dates for
forms. That way I can manage the format of the input and don't have to do
anything with it serverside, except check it's there (and check that end
dates come after start dates etc...).

There are a number of these knocking about on javascript code sites. Google
will find one for you easily enough.
 
E

Evertjan.

<%
Function changeUserDate(userDate)
temp = Split(userDate,"/")
strDay = temp(0)
strMonth = temp(1)
strYear = temp(2)
changeUserDate = strYear & "-" & strMonth & "-" & strDay
End Function

Response.Write changeUserDate(Request.Form("date"))
%>

<%
Response.Write changeUserDate(Request.Form("date"))

Function changeUserDate(userDate)
dim result(3)
temp = Split(userDate,"/")
result(2) = temp(0)
result(1) = temp(1)
result(0) = temp(2)
changeUserDate = Join(result,"-")
End Function
%>
 
M

Mike Brind

Evertjan. said:
<%
Response.Write changeUserDate(Request.Form("date"))

Function changeUserDate(userDate)
dim result(3)
temp = Split(userDate,"/")
result(2) = temp(0)
result(1) = temp(1)
result(0) = temp(2)
changeUserDate = Join(result,"-")
End Function
%>

Now that I like :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top