Greetings from Rio de Janeiro, Brazil!

I cannot understand this:

$date = '14-01-2006';
$fomatted = date('Y-m-d', strtotime($date));

How do I put input from the form (field names: day, month, year)
in $date, that is, the variables $year, $month and $day?

Regarding the second option:
Where do I put (date) precisely?
I cannot also understand this:
VALUES (DATE_FORMAT($date, '%Y-%m-%d'))
Where do I put it?

Thanks for your help.

    GlauSP wrote:

    Greetings from Rio de Janeiro, Brazil!

    I cannot understand this:

    $date = '14-01-2006';
    $fomatted = date('Y-m-d', strtotime($date));

    How do I put input from the form (field names: day, month, year)
    in $date, that is, the variables $year, $month and $day?

    Regarding the second option:
    Where do I put (date) precisely?
    I cannot also understand this:
    VALUES (DATE_FORMAT($date, '%Y-%m-%d'))
    Where do I put it?

    Thanks for your help.

    Ok...first of all the original form was only one text field as I understand it. Besides that, the form either uses POST or GET depending on which you choose. For example if you use POST you get the variables by $variable = $_POST['field name']

    The VALUES(DATE_FORMAT.... is run on a MySQL database that is set up to store these values. You have to set up a connection to this database and execute the query.

      I am using three drop down menus for year, month and day.
      I only need to know how to write correctly 'year', 'month' and 'day',
      the names of the form fields, in $date_input.

      $date_input = 'year-month-day';
      $due_date = date('Y-m-d',strtotime($date_input));

      Is it?

        $date_input = 'year-month-day';

        Is it?

          Ok...do this

          if(isset($_POST['submit'])){
          $date = $_POST['day'].'-'.$_POST['month'].'-'.$_POST['year']; 
          $fomatted = date('Y-m-d', strtotime($date));
          }
           

          Inside If statement run query to your database using $formatted

          Your form tag should look like....

          <form name="name" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
          
          //FORM CONTENTS
          
          <submit name="submit" value="Submit">
          </form>

            The result is always 31.12.1969.
            But in the flat database I see 2026-07-30.

              From www.php.net/date:

              "The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows)."

              Does this apply to my problem?

                Simply put: No. That deals with Timestamps, not date-stamps. The difference is if you create a timestamp, you can use that with the [man]date/man function to put that timestamp into any format (date and time) from an integer.

                For your purposes, that really doesn't apply to you.

                If you've got 3 drop-downs (Month, Day, Year) and you want to format a string like YYYY-Month-Day, honestly it's as easy as:

                <?php
                $date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
                echo $date; // Just to show the formatted date

                There is no need to use the [man]date/man function to insert it into a mySQL database. You can just use the properly formatted string (see 4 lines up). It's actually a lot easier than we've been telling you, and I just now realized it. Sorry.

                  I have put it so:

                  $date_input = $POST['day'].'-'.$POST['month'].'-'.$_POST['year'];
                  $formatted_date = strftime($message_settings['time_format'], $date_input);

                  But it does not work.
                  I always get 31.12.1969.

                  I'm using a flat database.

                    Thank you very much for your patience.
                    I have fixed the problem following your precise guidance.

                    How can I test php scripts on my computer itself, that is, without uploading them to a server and doing it online?

                      Install Apache (or IIS if you're using windows) and PHP. Then just go!!

                      There are plenty of tutorials for doing this online....

                        Write a Reply...