Thread: Date handling

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Lier, Antwerpen, Belgium
    Posts
    2
    Rep Power
    0
    Hi ;-)
    I'm creating a simple intranet application with PHP/mySQL. In this application, I have a form: in this form there are fields with dates. In belgium, dates are stored in the form dd/mm/yyyy. MySQL requires the dates to be stored as yyyy-mm-dd. Users can change the fields manually. Some use dd/mm/yy others d/mm/yy etc... When I update my tables, the date values are all wrong of course. One solution is to make a two digit field for the days, a two digit field for the month... (and use select boxes) but this is more work Does anyone know how an elegant way to convert "european (belgian) dates" to the required yyyy-mm-dd ?
    Thank you
    Guy
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    2
    Rep Power
    0
    I thought about two ways to do this:
    The first is this:


    $standard_date = ereg_replace( "(..).(..).(....)", "2-1-3", $belgium_date );


    This is more "elegant" and does all in a single instruction, but do not work if the user insert dates with a non-fixed format (i mean,the date 02/01/1999 can be written also 2/1/99).

    Instead you can use:

    list( $day, $month, $year ) = split( '/', $belgium_date );
    $standard_date = $year + "-" + $month + "-" + $day;

    this gives you also the three variables that you can compose as you like. Also this will work even if the user enters dates using a non-fixed format.

    I have not tested it, but i'm pretty sure they're right.

    Hope it helps,
    =KL=



  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    33
    Rep Power
    15
    nice example, but it doesn''t work !!

    now this function count all dates from
    months and days and years together.
    for instance :
    03/12/1999
    $standard_date is her 2014 !! ;-)

    who has a proper working example ??
    at first look i thought it would work,
    but tested it and it doesn't !

    i'm curious,

    Jan The Netherlands.

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    33
    Rep Power
    15
    i am used to other languages,
    and replied to quickly,
    the "+" must be a "." that's what's wrong
    in the example :-))

    so
    $year + "-" + $month + "-" + $day;
    must be
    $year."-".$month."-".$day

    sorry for my earlier remark, but
    now this example is complete and works
    for all people :-)

    Jan.

Similar Threads

  1. database date selection problem
    By kidsleep in forum MySQL Help
    Replies: 0
    Last Post: January 31st, 2004, 11:50 AM
  2. date addition problem
    By strange1 in forum PHP Development
    Replies: 3
    Last Post: October 6th, 2003, 05:01 PM
  3. Javascript date validation: advance to next valid date
    By TruckStuff in forum JavaScript Development
    Replies: 2
    Last Post: September 19th, 2003, 12:21 PM
  4. HTML Form not passing date value
    By XyberCom in forum PHP Development
    Replies: 14
    Last Post: September 14th, 2003, 02:18 PM
  5. UNIX mktime to mySQL date or date
    By mediaworks in forum PHP Development
    Replies: 5
    Last Post: June 24th, 2003, 03:55 AM

IMN logo majestic logo threadwatch logo seochat tools logo