954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing string to date help

I have made a script that gets only friday and puts them in a drop down but now i dont want to upload it into the datbase as a string i need it as timestamp so i can filter and order for current day and such.

here is the form

<?php
echo "<form action='".$_SERVER['php_self']."' method='post'> ";
print "<select name=\"start\" size=\"1\">"; 
print "<option value=\"Select Week\" selected>Select Week</option>"; 
for($i=0; $i<=6; $i++){ 
$num = date("d M Y", strtotime('next friday +'.$i.' week')); 
print"<option value=\"{$num}\">{$num}</option> \n"; 
} 
print "</select>";
echo "<input name='Submit' type='submit' id='start' value='Send Day'>";
echo "</form>";


and here is the upload to database part

$fridate = $_POST['start'];
$create = "INSERT INTO day (day) VALUES ('$fridate')";
$query=mysql_query($create);
if (!$query)
  echo $create."makes an error:".mysql_error();
?>


can anyone please help me to get the timestamp for the day so i can save into the database as date and not string?

ripper1510
Newbie Poster
10 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Use php strtotime() function on the $fridate variable prior to the insert.
http://us3.php.net/strtotime

buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
 

I have tried all the ways and havent been able to figure it out can you please help some more and show me(im kinda thick)?

ripper1510
Newbie Poster
10 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Try this out, prior to insert query:

$fridate=date('Y-m-d h:i:s',strtotime($fridate));
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
 

Amazing. It works. Thank you very much. I got close

$fridate2 = date('d F Y', strtotime('$fridate'));

You good man.

This site is amazing. The best

ripper1510
Newbie Poster
10 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You