Count date using Mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kill_bill
Forum Newbie
Posts: 6
Joined: Tue Jun 28, 2005 10:17 pm
Location: Malaysia
Contact:

Count date using Mysql

Post by kill_bill »

I got problem to view my table divided by expired date... so how to make a list of table that can divide the data by date...

for example..
1. list of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List

I have table with date, but what kind of mysql command can divide them by expired date if so, actually i'm newbie here... perhaps i can get any solution.. thanks..
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Do you want a single query?
User avatar
kill_bill
Forum Newbie
Posts: 6
Joined: Tue Jun 28, 2005 10:17 pm
Location: Malaysia
Contact:

Post by kill_bill »

yeah.. anything that can make me feel better.. if single way help.. it will be my pleasure if you can help me..
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Re: Count date using Mysql

Post by harrisonad »

kill_bill wrote: 1. list of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data['title'];
	$expiry_date = $data['expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left <= 7)
		$recent_list[] = $title;
	elseif($days_left > 7 && $days_left <= 14)
		$alert_list[] = $title;
	elseif($days_left > 14)
		$super_alert_list[]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
lled Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data['title'];
	$expiry_date = $data['expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left <= 7)
		$recent_list[] = $title;
	elseif($days_left > 7 && $days_left <= 14)
		$alert_list[] = $title;
	elseif($days_left > 14)
		$super_alert_list[]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
y_date = $data['expiry_date'];
$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
if($days_left <= 7)
$recent_list[] = $title;
elseif($days_left > 7 && $days_left <= 14)
$alert_list[] = $title;
elseif($days_left > 14)
$super_alert_list[]= $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
< 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data['title'];
	$expiry_date = $data['expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left <= 7)
		$recent_list[] = $title;
	elseif($days_left > 7 && $days_left <= 14)
		$alert_list[] = $title;
	elseif($days_left > 14)
		$super_alert_list[]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
; 7 && $days_left <= 14)
$alert_list[] = $titl expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] = $title;
	elseif($days_left &gt; 7 &amp;&amp; $days_left &lt;= 14)
		$alert_list&#1111;] = $title;
	elseif($days_left &amped date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_d"kill_bill"]
1. list of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data['title'];
	$expiry_date = $data['expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left <= 7)
		$recent_list[] = $title;
	elseif($days_left > 7 && $days_left <= 14)
		$alert_list[] = $title;
	elseif($days_left > 14)
		$super_alert_list[]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
te < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] = $title;
	elseif($days_left &gt; 7 &amp;&amp; $days_left &lt;= 1of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] = $title;
	elseif($days_left &gt; 7 &amp;&amp; $days_left &lt;= 14)
		$alert_list&#1111;] = $title;
	elseif($days_left &gt; 14)
		$super_alert_list&#1111;]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
"kill_bill"]
1. list of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data['title'];
	$expiry_date = $data['expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left <= 7)
		$recent_list[] = $title;
	elseif($days_left > 7 && $days_left <= 14)
		$alert_list[] = $title;
	elseif($days_left > 14)
		$super_alert_list[]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
[/php:1:64; 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'tibe put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] = $title;
	elseif($days_left &gt; 7 &amp;&amp; $days_left &lt;= 14)
		$alert_list&#1111;] = $title;
	elseif($days_left &gt; 14)
		$super_alert_list&#1111;]=  $title;
}
// now put array lists to select boxes
/te > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'exlt; 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=my"kill_bill"]
1. list of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] = $title;
	elseif($days_left &gt; 7 &amp;&amp; $days_left &lt;= 14)
		$alert_list&#1111;] = $title;
	elseif($days_left &gt; 14)
		$super_alert_list&#1111;]=  $titlut in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] = $title;
	elseif($days_left &gt; 7 &amp;&amp"kill_bill"]
1. list of recent file for expired date < 7 days will be put in a list called Recent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = &quote;SELECT * FROM tablename&quote;; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data&#1111;'title'];
	$expiry_date = $data&#1111;'expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left &lt;= 7)
		$recent_list&#1111;] ecent List
2. List of expired date > 7 and < 14 days will be put in a list called Alert List
3. List of expired date > 14 days will be put in a list called Super Alert List
[/quote]
I think you can accomplish this many ways. Here is an example:

Code: Select all

// prepare 3 arrays for different lists
$recent_list = $alert_list =$super_alert_list = array();
// get all items
$query = "SELECT * FROM tablename"; 
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
	$title = $data['title'];
	$expiry_date = $data['expiry_date'];
	$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
	if($days_left <= 7)
		$recent_list[] = $title;
	elseif($days_left > 7 && $days_left <= 14)
		$alert_list[] = $title;
	elseif($days_left > 14)
		$super_alert_list[]=  $title;
}
// now put array lists to select boxes
// ... i hope you know your way home from here
User avatar
kill_bill
Forum Newbie
Posts: 6
Joined: Tue Jun 28, 2005 10:17 pm
Location: Malaysia
Contact:

Post by kill_bill »

Code: Select all

$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better
Can you give me that potion please.. i'm so stuck rite now...thanks/ user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanksve me that potion please.. i'm so stuck rite now...thanksdate); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanks$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanks; // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanksff(date('Y-m-d',$expiry_date); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanks$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanksdate('Y-m-d',$expiry_date); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanksything better

Can you give me that potion please.. i'm so stuck rite now...thankspotion please.. i'm so stuck rite now...thanksr function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanks$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanksng better

Can you give me that potion please.. i'm so stuck rite now...thanks$days_left = getDateDiff(date('Y-m-d',$expiry_date); // user function or anything better

Can you give me that potion please.. i'm so stuck rite now...thanks
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Code: Select all

function getDateDiff($date1,$date2) {    
    $secondsdifference = $date2 - $date1;     
    $daysdifference = bcdiv($secondsdifference,86400);            
    return $daysdifference;
}
ndsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
secondsdifference,86400);
return $daysdifference;
}
[/php:1:69b94703 $secondsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}

function getDateDiff($date1,$date2) {
$secondsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
econdsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
($date1,$date2) {
$secondsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}

function getDateDiff($date1,$date2) {
$secondsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
ate1,$date2) {
$secondsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
[/php:erence,86400);
return $daysdifference;
}
fference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}

function getDateDiff($date1,$date2) {
$secondsdifference = $date2 - $date1;
$daysdifference = bcdiv($secondsdifference,86400);
return $daysdifference;
}
Post Reply