Jump to content

Date - Using If Statements


peter_anderson

Recommended Posts

MySQL has some very good date and time comparison and arithmetic functions you can use right in the query string. Have a look at these.

 

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Thanks,

 

How do I get the results from the MySql date time function query?

 

Heres what I've got so far.

<?php
//some was stripped
	// date
	$today_date = date("Y-m-d");
	// query
	$q = "SELECT STR_TO_DATE(date, '%j/%M/%Y') FROM `orders` WHERE id='$orderid' AND customer='$email'";
	$rs = $sql->query($q);
	$r = $rs->fetch_assoc();
	$order_date = $r['date'];
	// compare dates
	function date_diff($date1, $date2){ 
		$current = $date1; 
		$datetime2 = date_create($date2); 
		$count = 0; 
		while(date_create($current) < $datetime2){ 
			$current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current))); 
			$count++; 
		} 
		return $count; 
	} 
	echo(date_diff('2010-01-01', $order_date)." days <br \>"); 
	exit();
?>

 

How do I get the result of $q?

 

Thanks

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.