Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2014
    Posts
    35

    Unanswered: format a date from a form variable

    I am developing a php/mysql database.

    On one page I extract data between two dates so have a form with two variables 'startdate' and 'enddate' and a submit button. I can get the table of results I want but I also want a line above the table that says something like "The following data is from startdate to enddate" where the startdate and enddate are in the format day month year (eg 10 January 2015)

    If I use <?php echo $_POST["startdate"]; ?> then I get yyyy-mm-dd - How can I format this correctly or what is a better method?

    Thanks.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Use the PHP date function with the appropriate format mask.

    to capture the data consider usi g a Javascript date 'widget', theres plenty to choose from many are free to use. But if you do use such a widget always validate the incoming data to make certain that it is a date and the values are 'sane', ie in a range that youd expect. never trust data sent by a PHP (or any web) form, its just too easy to frig. You should also be taking steps to check for possible SQL injection attacks.

    If you are using the SQL BETWEEN construct make certain the first parameter is less than or equal to the second parameter
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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