Inserting date into mysql
Moderator: General Moderators
- mhouldridge
- Forum Contributor
- Posts: 267
- Joined: Wed Jan 26, 2005 5:13 am
ok, a little bit different than the sample I posted your situation is:
try:
try:
Code: Select all
$row = mysql_fetch_array($sql); //get a row from our result set
$dateone = $row['start_date'];
$datetwo = $row['end_date'];
$daysleft = ((strtotime($datetwo) - strtotime($dateone))/86400);
echo $daysleft;- mhouldridge
- Forum Contributor
- Posts: 267
- Joined: Wed Jan 26, 2005 5:13 am
- mhouldridge
- Forum Contributor
- Posts: 267
- Joined: Wed Jan 26, 2005 5:13 am
- mhouldridge
- Forum Contributor
- Posts: 267
- Joined: Wed Jan 26, 2005 5:13 am
Code: Select all
$today = date("Y-m-d");why not let MySQL do that dirty stuff. Keeps your PHP clean:
all in the manual: http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html
search for DATEDIFF on that page
Code: Select all
SELECT DATEDIFF('2003-11-20','2004-12-31');search for DATEDIFF on that page
- mhouldridge
- Forum Contributor
- Posts: 267
- Joined: Wed Jan 26, 2005 5:13 am
Hi,
I wonder if you could help me with a for loop. Here is the code;
I want to display the days left in my $daysleft value for the loop. It is not working yet.
I wonder if you could help me with a for loop. Here is the code;
Code: Select all
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($sql); //get a row from our result set
$today = date("Y-m-d"); // Set today's date as variable
$notify = 7; // Set notify variable to 7
$datetwo = $row['end_date']; //set dattwo variable to the field value from the query
$daysleft = ((strtotime($datetwo) - strtotime($today))/86400);
echo "<TR bgcolor=\"efefef\" onmouseover=this.className=\"test2\" onmouseout=this.className=\"test\" class=\"test\" onclick=this.className=\"test3\" class=\"test3\">\n";
echo "<TD><a href='viewasset.php?varl=".$row['id']."' class=\"blue5\">".$row['id']."</a></font></TD><TD>".$row['name']."</TD><TD>".$row['start_date']."</TD><TD>".$row['end_date']."</TD><TD>".$daysleft."</TD>\n";
echo "</TR>\n";
}
echo "</TABLE>\n";- trukfixer
- Forum Contributor
- Posts: 174
- Joined: Fri May 21, 2004 3:14 pm
- Location: Miami, Florida, USA
DATEDIFF() was added in MySQL 4.1.1. - if your mysql is < 4.1.1 you're out of luckpatrikG wrote:why not let MySQL do that dirty stuff. Keeps your PHP clean:
all in the manual: http://dev.mysql.com/doc/refman/4.1/en/ ... tions.htmlCode: Select all
SELECT DATEDIFF('2003-11-20','2004-12-31');
search for DATEDIFF on that page