Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2003, 01:10 AM
Authorized User
 
Join Date: Jun 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tgopal
Default how to convert string to date

hai pal,

how to convert string to date and how to check the given date is < or > of current date.
thanks in advance.

by
gopal
 
Old June 26th, 2003, 07:46 AM
Authorized User
 
Join Date: Jun 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tgopal
Default

Thanks guys i found the solution fot it
The sample code i used is
<HTML>
<FORM>

<INPUT type="text" name="date1" size=12>
<INPUT type="text" name="date2" size=12>
<input type="button" name="Check" value="Check" onClick="checkDate()">
</FORM>
<SCRIPT language="javascript">

function checkDate(){

var datevalue1=document.forms[0].date1.value;
var datevalue2=document.forms[0].date2.value;

var day1=datevalue1.substring(0,2);
var month1=datevalue1.substring(3,6);
var year1=datevalue1.substring(7,11);

var day2=datevalue2.substring(0,2);
var month2=datevalue2.substring(3,6);
var year2=datevalue2.substring(7,11);

month1=changeFormatStringtoNumber(month1);
month2=changeFormatStringtoNumber(month2);

var d1=new Date(year1,month1,day1);
var d2=new Date(year2,month2,day2);

if(d1>d2)
alert ("DATE1");
else
alert("DATE2");
}

function changeFormatStringtoNumber(monthval){
if(monthval=="JAN"){
monthval=0;
}
else if (monthval=="FEB") {
monthval=1;
}
else if (monthval=="MAR") {
monthval=2;
}
else if (monthval=="APR") {
monthval=3;
}
else if (monthval=="MAY") {
monthval=4;
}
else if (monthval=="JUN") {
monthval=5;
}
else if (monthval=="JUL") {
monthval=6;
}
else if (monthval=="AUG") {
monthval=7;
}
else if (monthval=="SEP") {
monthval=8;
}
else if (monthval=="OCT") {
monthval=9;
}
else if (monthval=="NOV") {
monthval=10;
}
else if (monthval=="DEC") {
monthval=11;
}
return(monthval);
}
</SCRIPT>
</HTML>
 
Old March 18th, 2008, 03:33 AM
Registered User
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys,
Thanks all of you, your solution helped me to complete my current web project!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string to Date rprasad012 ASP.NET 1.0 and 1.1 Basics 1 March 19th, 2008 07:07 AM
convert string to date collie SQL Server 2000 4 March 15th, 2007 03:50 PM
convert string to date deeptibg SQL Server DTS 1 December 22nd, 2005 08:47 PM
Convert Part of String to Date twsinc Access VBA 6 October 20th, 2004 03:31 PM
Convert String Date to Date for a SQL Query tdaustin Classic ASP Basics 4 July 7th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.