Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Dating Game. 1

Status
Not open for further replies.

Deltaflyer

Programmer
Oct 11, 2000
184
GB
Hiya everyone, is there a programmer in the house???

I am trying to create a web page that goes away and queries my database for entries between two dates. This is not a problem ( despite my having to use SQL7 ), the query works it returns all the values i want etc....etc....

My boss suddenly decides though, the people who are using my page are not as intelligent as i assumed, he reckons that they will put the startdate in the enddate box and vice versa, he has asked me to write a little java function that will check that this doesn't happen.

I though that the below coding would do the job, it doesn't.

Can anybody tell me why or show me the right way of comparing dates.

Thanks In Advance, Deltaflyer
P.S. checkdate(formobj.cdate ....etc....) is validating that the correct format has been observed, i.e. dd/mm/yy.


var cdate1 = formobj.cdate1.value
var cdate2 = formobj.cdate2.value

if (checkdate(formobj.cdate1.value) == 1)
{
alert("start date is invalid. \n format dd/mm/yy.")
return
}

if (checkdate(formobj.cdate2.value) == 1)
{
alert("end date is invalid. \n format dd/mm/yy.")
return
}

if (cdate1 < cdate2)
{
alert(&quot;start date after end date - Big Error - Stop It!!!&quot;)
return
}
formobj.submit()
DeltaFlyer - The Only Programmer To Crash Land In Style.
 
You are trying to compare two simple strings...try making them into dates before you compare them (new Date()) jared@aauser.com
 
Nice one Mr Jared, much appreciated.

Later, DeltaFlyer DeltaFlyer - The Only Programmer To Crash With Style.
 
Sorry, it's me again. :p

When i tried the coding :

if (new Date(cdate1) > new Date(cdate2))
{
alert(&quot;start date after end date - Big Error - Stop It!!!&quot;)
return
}


it works fine but it is using mm/dd/yy format, is there anyway of converting this to dd/mm/yy format as this is the format i am using on my pages.
DeltaFlyer - The Only Programmer To Crash With Style.
 
Couldn't find anything useful :-( ( at least nothing useful that is compatible with my meagre knowledge ) so i cheated :-0.

I sliced my dates into day,month and year and did a manual check on them. It's dirty coding but it works, when i have more time to figure it out properly i will, for now though my boss is happy.

You solved another problem for me as well, i have been looking for JScript Language Reference for a few weeks now, with that under my belt i should be laughing. LOL

Once again Jared, thanks.

DeltaFlyer DeltaFlyer - The Only Programmer To Crash With Style.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top