Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Date help...

  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date help...

    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.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    /^(\d{2})(\d{2})(\d{4})$/

    If you want it simple. It doesn't make sure the date written is valid though.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •