473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 :-)

Oct 4 '06 #1
3 5722
"David" <da*********@scene-double.co.ukwrote in message
news:11**********************@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
Oct 4 '06 #2
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)
Oct 4 '06 #3
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@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
Oct 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: oliver | last post by:
hi there i'm experimanting with imaplib and came across stringts like (\HasNoChildren) "." "INBOX.Sent Items" in which the quotes are part of the string. now i try to convert this into a...
2
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces,...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
4
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
5
by: Sen Haerens | last post by:
I'm using string.split(/^$/m, 2) on a curl output to separate header and body. There’s an empty line between them. ^$ doesn’t seem to work... Example curl output: HTTP/1.1 404 Not Found...
6
by: Saurabh | last post by:
Hi everyone, I am looking for some expert advise to get me out of trouble. I am looking for a solution in C# which will allow me to split the below string in the format provided. The...
2
by: Shawn Minisall | last post by:
I'm trying to unpack a list of 5 floats from a list read from a file and python is telling me 5 variables are too many for the string.split statement. Anyone have any other idea's? NOTE: the only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.