473,405 Members | 2,310 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,405 software developers and data experts.

Compare dates - iso format

Hi everybody

The date values entered in my text boxes (startDate and endDate) in my form are in ISO format YYYY-MM-DD.

Could you please help me and explain how I can compare the date values to make sure the start date is smaller than the end date?

I have something like the following, but it is not working (I guess due to ISO format)

Expand|Select|Wrap|Line Numbers
  1. if ( new Date(document.SearchFrm.startDate.value) > new Date(document.SearchFrm.endDate.value)){
  2. alert ("Start Date is greater");
  3. }

Any tips is extremely appreciated,
Maral
Nov 17 '07 #1
5 2777
acoder
16,027 Expert Mod 8TB
Take the values and use split("-") to split the string into an array, then use setFullYear to set the date - see link.
Nov 17 '07 #2
Take the values and use split("-") to split the string into an array, then use setFullYear to set the date - see link.

Thank you for your advice.
Maral
Nov 18 '07 #3
acoder
16,027 Expert Mod 8TB
You're welcome. Let us know if you hit any problems. Good luck!
Nov 18 '07 #4
Hi

Appreciate your help and advice with the problem I have faced. My code is as follows:

Expand|Select|Wrap|Line Numbers
  1. function Compare() {
  2.  
  3.     var StartDateSt=document.SearchFrm.startDate.value;
  4.     var EndDateSt=document.SearchFrm.endDate.value;
  5.  
  6.     StartDateSt = StartDateSt.split("-");
  7.     EndDateSt = EndDateSt.split("-");
  8.  
  9.     var StartDate=new Date();
  10.     StartDate.setFullYear(StartDateSt);
  11.  
  12.     var EndDate=new Date();
  13.     EndDate.setFullYear(EndDateSt);
  14.  
  15.    alert(EndDate);
  16.    alert(StartDate);
  17.  
  18. }

As the code is run, the two alert boxes return NaN.


Trying to solve the problem in a different way, this time I let the user enter the date the usual way dd/mm/yyyy and use something like :

Expand|Select|Wrap|Line Numbers
  1.     var StartDate = new Date(StartDateSt);
  2.     var StartDateYear = StartDate.getYear();
  3.     var StartDateMonth = StartDate.getMonth();
  4.     var StartDateDay = StartDate.getDate();  

and then connect the different parts through "-". The problem I face here is that, the entered date in the textbox of my Web page is only processed correctly if it is entered as mm/dd/yyyy; Is this the default setting of dates in Javascript?

How can I change the date format so the user can enter it as dd/mm/yyyy?


Thank you in advance
Maral
Nov 24 '07 #5
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. StartDate.setFullYear(StartDateSt);
should be
Expand|Select|Wrap|Line Numbers
  1. StartDate.setFullYear(StartDateSt[0],StartDateSt[1],StartDateSt[2]);
Nov 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: alexis | last post by:
Hi, In a form I have the curent date <input name="datetoday" type="hidden" value="<? echo date("d/m/Y"); ?>"> and <input type=text name="datebox" size=15> The date format is d/m/Y...
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...
9
by: Rimuen | last post by:
Have two text form with dates i need to compare before submitting, the second should always be a date later the first one. Anyone have a script for this ?? Thanks.......
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
5
by: DW | last post by:
I have a query in Access 2003 that has the following criteria SELECT tblOrder.SessionDate, tblMenus.Item_Name, tblOrder.Type, Format$(tblorder!SessionDate,"Short Time") AS SessionTime,...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: ar555 | last post by:
I have a page with two textfields for dates (dateFrom, dateTo) which user inputs from a small popup calendar. Dates are in dd/mm/yyyy format. When user clicks on submit button, function is called to...
1
by: vrparekh | last post by:
in my webapplication,user pick date in dd/mm/yy format, and i want to compare that date with another date using compare validator but compare validator compare the dates using mm/dd/yy format. ...
2
by: juan ortiz | last post by:
DB2 Two dates in a DB2 table with regular yyyy-mm-dd format I want format DATE1 as yymm (when you show me how to do it) to compare DATE1 to DATE2 ( will also format this 2nd date as yymm)...
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: 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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.