| Author |
JavaScript Date Formats and new Date()
|
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Originally all our dates were in the format MM/dd/yyyy across the board. The client wants them MM-dd-yy. I ran into some JavaScript bugs after the change. Specifically...
I'm pulling the date string from a text input. I'm a) not sure why JavaScript will parse one and not the other and b) what I can do to get JavaScript to parse the latter.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56540
|
|
|
I hate dealing with dates with a passion. Can you use the date parsing utility function provided by the jQuery UI datepicker? If not, you might need to regex the string and reform it to something that Date() likes. Icky icky icky.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Tom Varga
Greenhorn
Joined: Aug 09, 2010
Posts: 8
|
|
Convert your date string into an accepted date format:
See the following pages, they will be useful:
Date object,
Regular Expression (RegExp) object.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Bear Bibeault wrote:I hate dealing with dates with a passion. Can you use the date parsing utility function provided by the jQuery UI datepicker? If not, you might need to regex the string and reform it to something that Date() likes. Icky icky icky.
Perfect!
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
I know I'm being an old fuddy-duddy, but is that code Y2K-compliant? Tom Varga's code wasn't... but perhaps you won't be expecting dates before 2000?
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Paul Clapham wrote:I know I'm being an old fuddy-duddy, but is that code Y2K-compliant? Tom Varga's code wasn't... but perhaps you won't be expecting dates before 2000?
I think anytime you go to a 2 digit year, Y2K goes out of the window. We're not expected to have any dates prior to 2000 though. We brought this up to the client.
|
 |
 |
|
|
subject: JavaScript Date Formats and new Date()
|
|
|