Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   Split, convert date question ?? (http://www.velocityreviews.com/forums/t802136-split-convert-date-question.html)

David 10-04-2006 12:03 PM

Split, convert date question ??
 
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 :-)


Mike Brind 10-04-2006 12:26 PM

Re: Split, convert date question ??
 
"David" <davidgordon@scene-double.co.uk> wrote in message
news:1159963404.439496.242950@e3g2000cwe.googlegro ups.com...
> 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.

--
Mike Brind



Evertjan. 10-04-2006 02:28 PM

Re: Split, convert date question ??
 
On 04 okt 2006, you wrote in microsoft.public.inetserver.asp.general:

> <%
> 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
%>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Mike Brind 10-04-2006 02:47 PM

Re: Split, convert date question ??
 
"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns9852A7924210Eeejj99@194.109.133.242...
> On 04 okt 2006, you wrote in microsoft.public.inetserver.asp.general:
>
>> <%
>> 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
> %>


Now that I like :-)

--
Mike Brind




All times are GMT. The time now is 04:21 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.