Jump to content

mktime() function issue


JNorman

Recommended Posts

Hi Guys,

 

In building a new website i am requesting that people input their date of births using a drop down for the Day and the month and a text box for the year. I am then converting these dates into a times stamp using the mktime() function in the processing. In most cases, it is successful and returns to timestamp however other times it will return 0. It seems to happen most when the dates are significantly less than 1950. My database field is set to text so it should accept any value. Thanks Guys.

 

Form:

<select name="day" id="day">
                              <option selected="selected">1</option>
                              <option>2</option>
                              <option>3</option>
                              <option>4</option>
                              <option>5</option>
                              <option>6</option>
                              <option>7</option>
                              <option>8</option>
                              <option>9</option>
                              <option>10</option>
                              <option>11</option>
                              <option>12</option>
                              <option>13</option>
                              <option>14</option>
                              <option>15</option>
                              <option>16</option>
                              <option>17</option>
                              <option>18</option>
                              <option>19</option>
                              <option>20</option>
                              <option>21</option>
                              <option>22</option>
                              <option>23</option>
                              <option>24</option>
                              <option>25</option>
                              <option>26</option>
                              <option>27</option>
                              <option>28</option>
                              <option>29</option>
                              <option>30</option>
                              <option>31</option>
                            </select></label>
                           
                         <select name="month" id="month">
                           <option value="1" selected="selected">January</option>
                           <option value="2">Febuary</option>
                           <option value="3">March</option>
                           <option value="4">April</option>
                           <option value="5">May</option>
                           <option value="6">June</option>
                           <option value="7">July</option>
                           <option value="8">August</option>
                           <option value="9">September</option>
                           <option value="10">October</option>
                           <option value="11">November</option>
                           <option value="12">December</option>
                         </select>
                          <input name="year" type="text" id="year" size="4" maxlength="4" />

 

 

Processing:

$dobtimestamp = mktime(0, 0, 0, $_POST["month"], $_POST["day"], $_POST["year"]);

 

Appreciate your help!

 

James

Link to comment
https://forums.phpfreaks.com/topic/136822-mktime-function-issue/
Share on other sites

Unix Timestamps have their uses, mainly for figuring differences in date/times, but for storing fixed dates, especially birthdays, they are less than usable. They must also undergo a slow conversion when they are created or when they are output in any human readable form and this conversion is subject to errors if your server's time is set wrong, if your timezone settings are wrong, or if your timezone database is not up to date with the latest changes in DST start/stop dates or the server's time or timezone changes from the point when the timestamp was created and when it is used.

 

Use a DATETIME data type in your database. A DATETIME value will always be what you set it to.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.