SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP! Date input from web must conform with DATE of MySQL

    Ok, so ppl can add advertisements of upcoming events.
    I want them to input the date of the event, but the date must be input under a form MySQL can recognize which is DATE : yyyy-mm-dd

    Now how would I go about making sure the user enters the date like that?
    Select lists? If so how would I go about? FOrmating???


    Please help.!!!!
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  2. #2
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't force the user to do something that is unnatural for them. I would give them select boxes for the month, day and year and use the form data to create the date.

    PHP Code:
    function Date2MySQL($mm$dd$yyyy)
    {
      
    $MySQL_Date $yyyy "-" $mm "-" $dd;
      return  
    $MySQL_Date;


  3. #3
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Almost any format under the sun will work:
    http://www.php.net/manual/en/function.strtotime.php

    This converts to unix timestamp. There's a PHP and mySQL function to convert and/or work with a unix timestamp.

    Owen

  4. #4
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THanks.
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  5. #5
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a couple of thoughts...

    1. If you are concerned about speed, PHP standard (and MySQL) functions work much faster than user defined ones.

    2. Date formats can be confused quite easily (take American and British formats for instance) so I think it is best to have some foolproof system where the user is sure they are entering the day or the month (and year).

  6. #6
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made a dropdown list that display like: 13 Apr, 2003
    So it's not confusing and will submit the data the way it's supposed to.
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]


Bookmarks

Posting Permissions

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