Current location: Hot Scripts Forums » Programming Languages » PHP » Convert DATE to timestamp


Convert DATE to timestamp

Reply
  #1 (permalink)  
Old 09-15-09, 03:44 PM
cyberfolli cyberfolli is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-15-09, 03:53 PM
Nico's Avatar
Nico Nico is offline
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().
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Nico For This Useful Post:
cyberfolli (09-15-09)
  #3 (permalink)  
Old 09-15-09, 04:21 PM
cyberfolli cyberfolli is offline
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)'];
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-15-09, 04:27 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
cyberfolli (09-16-09)
  #5 (permalink)  
Old 09-15-09, 04:57 PM
cyberfolli cyberfolli is offline
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>&nbsp;</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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-15-09, 07:10 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
$stamp will probably have to be something like:

PHP Code:

$stamp=$_POST['month'].'/'.$_POST['day'].'/'.$_POST['year']; 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
cyberfolli (09-16-09)
  #7 (permalink)  
Old 09-15-09, 07:18 PM
Jcbones Jcbones is offline
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.

PHP Code:

$month $_POST['month'];

$day $_POST['day'];
$year $_POST['year'];

//Date stamp (type: Date) would be.
$stamp $year '-' $month '-' $day;

//Timestamp (type:Timestamp) would be.
$stamp date("Y-m-d H:i:s"mktime(0,0,0,$month,$day,$year));

//output of date = 2009-12-19
//output of timestamp = 2009-12-19 00:00:00 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
cyberfolli (09-16-09)
  #8 (permalink)  
Old 09-15-09, 07:24 PM
cyberfolli cyberfolli is offline
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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 09-16-09, 10:06 AM
cyberfolli cyberfolli is offline
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

Code:
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];

//Date stamp (type: Date) would be.
$stamp = $year . '-' . $month . '-' . $day; 
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year']; 
$reoccurr = $_POST['reoccurr'];
$title = $_POST['title'];
$department = $_POST['department'];
$notes = $_POST['notes'];
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 09-16-09, 10:08 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

$stamp mktime(000$month$day$year); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Nico For This Useful Post:
cyberfolli (09-16-09)
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert a numerical date into a string date? moroose PHP 3 05-12-08 08:36 AM
Convert Date Nikas PHP 4 01-01-08 12:07 PM
converting date-string to Date object UnrealEd Everything Java 4 05-15-07 07:20 PM
Convert timestamp to date with Date::Manip FiRe Perl 1 07-29-05 06:54 AM
date problem - convert eg. '06' to 'jun' tallpaul858 PHP 3 04-16-05 07:39 PM


All times are GMT -5. The time now is 10:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.