|
 |
asp_web_howto thread: date comparison with eg.
Message #1 by "Krishnanand K, J16 Chennai" <krishnanandk@m...> on Thu, 22 Feb 2001 11:34:01 +0530
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C09C95.40E0AC20
Content-Type: text/plain;
charset="iso-8859-1"
Hello all,
Suppose if I enter two dates even in dd/mm/yyyy format , it is
automatically converted to mm/dd/yyyy format in VBScript and I don't want
the clients to change the settings to dd/mm/yyyy
for my asp page to do proper validations and we can't expect that.
Because of this, if I want to check whether date1 is greater than date2 ,
i.e
if Cdate(date1)>Cdate(date2) then
error message
end if
I am not getting proper results. So is there any built-in function to
convert date to dd/mm/yyyy format . Formatdatetime function is not helping
out in this regard.
example .(dd/mm/yyyy format)
If date1= 9/1/2001
And date2= 13/1/2001
And in the vbscript if I type
If Cdate(date1) > Cdate(date2) then
Msgbox "date1 to be less than date2"
End if
Now what happens is 9/1/2001 is taken as mm/dd/yyyy (i.e 9th sept 2001)
And date2 is taken as 13/1/2001.(i.e. 13th jan 2001 that's OK )
Now when comparing, naturally date1 is > date2 which is not the proper
result.
So any way to treat date in dd/mm/yyyy format.
With regards
krishna
Message #2 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Thu, 22 Feb 2001 10:03:43 -0000
|
|
I assume you are telling your users to enter it in dd/mm/yyyy format
read the string in and split on "/", then you have an array with day, month,
year in it, and you can create a date from that
on the client:
<script language="javascript">
var sDate = document.all.datefield.value;
var aDate = sdate.split("/");
var dDate = new date(aDate[2], aDate[1], aDate[0]);
</script>
or on the server:
<%
dim sDate, aDate, dDate
sDate = request.form("datefield")
aDate = split(sDate, "/")
dDate = DateSerial(aDate(2), aDate(1), aDate(0))
%>
Message #3 by "Krishnanand K, J16 Chennai" <krishnanandk@m...> on Thu, 22 Feb 2001 16:41:05 +0530
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C09CC0.261EF1F0
Content-Type: text/plain;
charset="iso-8859-1"
Thanks Alex Shiell,
I just followed ur logic and my problem is slolved. Thank you once
again.
krishna
-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Thursday, February 22, 2001 3:34 PM
To: ASP Web HowTo
Subject: [asp_web_howto] RE: date comparison with eg.
I assume you are telling your users to enter it in dd/mm/yyyy format
read the string in and split on "/", then you have an array with day, month,
year in it, and you can create a date from that
on the client:
<script language="javascript">
var sDate = document.all.datefield.value;
var aDate = sdate.split("/");
var dDate = new date(aDate[2], aDate[1], aDate[0]);
</script>
or on the server:
<%
dim sDate, aDate, dDate
sDate = request.form("datefield")
aDate = split(sDate, "/")
dDate = DateSerial(aDate(2), aDate(1), aDate(0))
%>
krishnanandk@m...
$subst('Email.Unsub')
|
|
 |