• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

convert text object to date where date-format is dynamic

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also you will have trouble when the user would enter 1-12-3
now which is the day,month,year?
 
gaurav chaudhary
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic