I want to be able to have a user enter an expiration date via a form. For example, I am building data that should no longer be available after a date that the user enters via a form.

What is the best approach? Did build something with fields for month, day, and year but it seems like there should be an easier way.....any ideas?

Thank you for the help.

    How do you save the info from the form?

    I would go for timestamp time(); Then compare form - timestamp with present timestamp

      Did you get the INSERT working then? Do you get a timestamp in the right sql-column?

        Yes, I have a timestamp field in the database. I guess I want to know the easiest way for a user to enter the timestamp in from a form?

        Lets say I have information stored in a database for a list of events that will be happening all month. I want to give the person who is entering the information in a form a way to manually set the expiration date (timestamp) to whatever day they would like.....

          First of all you need to get the time from the form. I take it thats not the problem. (See to it that the user can set the time and get it from $_POST['time'].) Then use strtotime() to get unix timestamp.

          $time = $_POST['time']; //this will get time from the form.
          $timestamp = strtotime($time); //this will make a timestamp of the time set in the form.

          Now you can use strftime() to show what the date in a way that people will understand..

            The easiest way is to allow the user to select a Month, Day, Year, Hour, Minute in drop-downs. [man]strtotime/man will only work with certain variations of dates and times. So if a user is different and writes it that is not a common format (like MM/DD/YYYY or DD.MM.YY) then strtotime() might not come back with a valid timestamp.

            The best way to do it is to provide drop-downs for each part of the date and time. Then use [man]mktime/man to create a unix-timestamp of that specific time.

            If you need to deal with timezones, you should ask them to either give you their timezone calculation (-5 for EST) or tell them to put the time in according to GMT (which is +/- 0 hours) and then you can later make the calculations based upon DST and timezone how many hours to shave off or add to that date.

              bpat1434 wrote:

              The easiest way is to allow the user to select a Month, Day, Year, Hour, Minute in drop-downs. [man]strtotime/man will only work with certain variations of dates and times. So if a user is different and writes it that is not a common format (like MM/DD/YYYY or DD.MM.YY) then strtotime() might not come back with a valid timestamp.

              The best way to do it is to provide drop-downs for each part of the date and time. Then use [man]mktime/man to create a unix-timestamp of that specific time.

              If you need to deal with timezones, you should ask them to either give you their timezone calculation (-5 for EST) or tell them to put the time in according to GMT (which is +/- 0 hours) and then you can later make the calculations based upon DST and timezone how many hours to shave off or add to that date.

              So that would be 5 droppdowns? I'm not convinsed. Is that really something you think a user likes to mess with every time he posts something. I'm not sure. Better to leave that to the user. Date(yyyymmdd):<input name="date" <!-- etc --> /> You can allways give the user a way to edit if ther is sometning wrong. Date or message.

              Furthermore I seem to recall that strtotime is able to handle strings. If the string is no good it's ease to check it:

              $date = 'some_date'; //maybe from $_POST['date']
              
              if (($timestamp = strtotime($date)) === false) {
                  echo "Fill out the form properly, $date is no date.";
              } else {
                  echo "Did you mean $date == " . date('l dS \o\f F Y h:i:s A', $timestamp);
              }
              

                Read the strtotime manual page. It will only handle the GNU Date Input Formats. So not every incarnation of dates that user puts in is valid.

                It's easier on the developer to supply drop-downs for a date, and let them input a time perhaps; however, it's easier on the user to just type in a date.

                The ultimate solution is to use a javascript library to give them a calendar and a clock to set which populates a read-only text area.

                  bpat1434 wrote:

                  Read the strtotime manual page. It will only handle the GNU Date Input Formats. So not every incarnation of dates that user puts in is valid.

                  It's easier on the developer to supply drop-downs for a date, and let them input a time perhaps; however, it's easier on the user to just type in a date.

                  The ultimate solution is to use a javascript library to give them a calendar and a clock to set which populates a read-only text area.

                  Well well, hopfully pepper have got some ideas of how to address the matter.

                    7 days later

                    Hopefully, otherwise he's singin' with his Lonely Heart Club Band....

                      Write a Reply...