Convert DATE to timestamp
09-15-09, 03:44 PM
Newbie Coder
Join Date: Jan 2004
Posts: 93
Thanks: 8
Thanked 0 Times in 0 Posts
Convert DATE to timestamp
HI I have found alot of timestamp to date functions and solutions but none that convert a date like 01/01/2009 to a timestamp
Basically I have a from that a user is choosing the date from a drop down menu day / month / year.. but once they choose that I need to take the date they have chosen and convert it to a timestamp..
I have found the reverse for display but not for converting.
Any help would be greatly appreciated.
09-15-09, 03:53 PM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
If the days and months come from separate drop downs, check mktime(). If it's all one string, check strtotime().
The Following User Says Thank You to Nico For This Useful Post:
09-15-09, 04:21 PM
Newbie Coder
Join Date: Jan 2004
Posts: 93
Thanks: 8
Thanked 0 Times in 0 Posts
So if I define the drop downs as month day year
when if goes to process the data I would use something like this? I have tried it it doesn't give me an error but the data is missing
$stamp = $_POST['Y-m-d H:i:s, mktime($hour, $minutes, $seconds, $month, $day, $year)'];
09-15-09, 04:27 PM
-
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
The $stamp code you posted won't work.
Please post the HTML and PHP code.
The Following User Says Thank You to wirehopper For This Useful Post:
09-15-09, 04:57 PM
Newbie Coder
Join Date: Jan 2004
Posts: 93
Thanks: 8
Thanked 0 Times in 0 Posts
PHP Code:
<form action="" method="post" name="verify" onsubmit="return ValidateRequiredFields();">
<div align="center">
<table width="500" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2">Please submit the following information.</td>
</tr>
<tr bgcolor="#CCCCCC">
<td>Date</td>
<td><select name="month">
<option value="1" selected="selected">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
</select>
<select name="day">
<option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><select name="year">
<option value="2009" selected="selected">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
</select></td>
</tr>
<tr bgcolor="#CCCCCC">
<td bgcolor="#FFFFFF"><strong>Reoccurring</strong></td>
<td bgcolor="#FFFFFF"><input name="reoccurr" type="checkbox" id="reoccurr" value="yes" /></td>
</tr>
<tr bgcolor="#CCCCCC">
<td>DaySpan</td>
<td><select name="day" id="day">
<option value="1" selected="selected">1</option>
</select></td>
</tr>
<tr bgcolor="#CCCCCC">
<td><strong>Title</strong></td>
<td><input name="title" type="text" id="title" size="80" /></td>
</tr>
<tr bgcolor="#CCCCCC">
<td bgcolor="#FFFFFF"><strong>department</strong></td>
<td bgcolor="#FFFFFF"><select name="department" id="department">
<?php
$sql = "SELECT * FROM categories order by fullName" ;
$query = mysql_query ( $sql );
while( $row = mysql_fetch_array ( $query )) {
echo " <option value=" . $row [ 'ID' ]. "> " . $row [ 'fullName' ]. "</option>" ;
}
?>
</select>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td><strong>Description</strong></td>
<td><textarea name="notes" cols="80" rows="10" id="notes"></textarea></td>
</tr>
<tr bgcolor="#CCCCCC">
<td> </td>
<td><input type="submit" name="submit" value="Submit!" /></td>
</tr>
</table>
</div>
</form>
<?php
} else {
$stamp = $_POST [ 'Y-m-d H:i:s, mktime($hour, $minutes, $seconds, $month, $day, $year)' ];
$reoccurr = $_POST [ 'reoccurr' ];
$title = $_POST [ 'title' ];
$department = $_POST [ 'department' ];
$notes = $_POST [ 'notes' ];
mysql_query ( "INSERT INTO `events` (stamp, reoccurr, title, department, notes) VALUES (' $stamp ',' $reoccurr ',' $title ',' $department ',' $notes ')" );
echo "<center> <a href=index.php>Return to calendar</a>" ;
}
?>
Last edited by wirehopper; 09-15-09 at 07:08 PM .
Reason: PHP tags
09-15-09, 07:10 PM
-
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
$stamp will probably have to be something like:
The Following User Says Thank You to wirehopper For This Useful Post:
09-15-09, 07:18 PM
Aspiring Coder
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You want at timestamp or a datestamp?
Timestamp includes the Time (example: 2009-09-10 23:13:51)<-pulled from MySQL database.
Date stamp does not include time (example: 2009-12-19)<- pulled from MySQL database.
I don't see any reason why you would want a timestamp which the user selects, unless you ask them to pass the Hour, Minute, and Second as well.
The Following User Says Thank You to Jcbones For This Useful Post:
09-15-09, 07:24 PM
Newbie Coder
Join Date: Jan 2004
Posts: 93
Thanks: 8
Thanked 0 Times in 0 Posts
THanks a bunch.. I will try it out and see if it pans out.. One of these days I will understand this stuff..
09-16-09, 10:06 AM
Newbie Coder
Join Date: Jan 2004
Posts: 93
Thanks: 8
Thanked 0 Times in 0 Posts
OK I am one step closer .. it works now and is entering the data..
Now i need to convert it to a unix date stamp "1252595920" instead of just a date in one field
09-16-09, 10:08 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
The Following User Says Thank You to Nico For This Useful Post:
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off