Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Split, convert date question ??

Reply
Thread Tools

Split, convert date question ??

 
 
David
Guest
Posts: n/a
 
      10-04-2006
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

 
Reply With Quote
 
 
 
 
Mike Brind
Guest
Posts: n/a
 
      10-04-2006
"David" <> wrote in message
news: 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


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      10-04-2006
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)
 
Reply With Quote
 
Mike Brind
Guest
Posts: n/a
 
      10-04-2006
"Evertjan." <> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert Julian date to Gregorian date Sam ASP .Net 1 04-27-2005 01:12 PM
Convert Julian Date to VB.NET date =?Utf-8?B?UmFqYQ==?= ASP .Net 1 11-12-2004 06:08 PM
how can I convert date infomation to a string just includes the date not the time wgan Java 7 07-08-2004 07:08 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
convert gregorian date to jalay date h_ghanaty ASP .Net 1 11-09-2003 06:02 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57