This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes convert text object to date where date-format is dynamic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "convert text object to date where date-format is dynamic" Watch "convert text object to date where date-format is dynamic" New topic
Author

convert text object to date where date-format is dynamic

gaurav chaudhary
Ranch Hand

Joined: Jun 24, 2002
Posts: 64
I have two text field used to enter dates. Now, I want to compare the date entered in these two text fields and return the result whether the first date is before the second date. The problem is that the format of the date entered in the text field is dynamic coming from the variable in the session from the jsp. Now, how do I convert this text to the date object and pass the format of the date also
thanks in advance
gaurav


gaurav
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Hai Gaurav,
You mean the user is allowed to enter the date in any format! if you really want to do this it is extreamly difficult to create the date object
because you need a lot of java script code to detect what the user had typed in the simplest way to do this will be RegExp.
I will prefer it to follow ISO standard always(YYYY-MM-DD)
OR
Keep 3 small text fields for each of the dates
OR
If you can restrict the user for a period(for eg 30 days ) pulldown menus will be the best solution


I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
also you will have trouble when the user would enter 1-12-3
now which is the day,month,year?
gaurav chaudhary
Ranch Hand

Joined: Jun 24, 2002
Posts: 64
No, actually you got me wrong......the problem is formatting a date object. Means, The user will enter the date in the format predefined by me only and I will know the format and can convey the same to javascript. But, how do I parse it because if the date format is mm/dd/yyyy then when I am creating the date object
var i=new Date("12/30/03");
it is working fine. Now, how do I convert the text entered in dd/mm/yyyy format to date object.
that was my original problem......sorry for not being clear initially
gaurav
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
make the date input called tex;
var tex=.........;
Parts = tex.split('/');
NewFormat = Parts[1]+'/'+ Parts[0]+'/'+ Parts[2];
Now the date will be in the format you want.
Eric
gaurav chaudhary
Ranch Hand

Joined: Jun 24, 2002
Posts: 64
That I know. The main problem is how do I create a new date object with the specified format of input date. I need to do this to compare with other date object in javascript. I need to know the function where the input string and the format (mm/dd/yyyy or dd/mm/yyyy) can be passed and which returns the date
thanks in advance
gaurav
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi gaurav,
why don't u just write ur own date comparsion by splitting date string with "/" sign and as you know the format u will know mm, dd, yyyy information.
i can give u the code tomorrow as i am not having it at home. meanwhile u can try urself. its not difficult.
regards
maulin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert text object to date where date-format is dynamic
 
Similar Threads
Convert a String with a date valus for Oracle
Disabling a text field when another text field has some input
JavaScript date help
How to Avoid Default Values for Double or Any Wrapper Class
Visual J++, calculate days difference