...

View Full Version : Date help...



ChimChim
01-12-2004, 10:38 PM
I'm using one of the date chooser's available at www.javascriptkit.com, the one from Denis Gritcyuk. I'm new to Javascript and I need to change the date format that is accepted. Here is the algorithm that is currently used, it takes a string and turns it into a date:

var re_date = /^(\d+)\-(\d+)\-(\d+)$/;

I need to have the date in the format of MMddyyyy.

Any help would be greatly appreciated, TIA.

liorean
01-12-2004, 11:37 PM
/^(\d{2})(\d{2})(\d{4})$/

If you want it simple. It doesn't make sure the date written is valid though.

ChimChim
01-13-2004, 12:33 AM
Thanks for you help. I understand how some of the regex works, is there a way to keep the leading zero for the month and/or day?

liorean
01-13-2004, 12:48 AM
This one REQUIRES the date to be written using exactly 2 digits for month, 2 digits for date, 4 digits for year. This is a string match. It will return a string, exactly as it looked in the original. So, it already preserves the leading zeroes.

ChimChim
01-13-2004, 05:27 PM
Its working perfectly now. I had a problem with the Date constructor...I had to put the RegEx.1,2,and 3 in the right order.

Thanks for you help.

ChimChim



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum