1

I want to keep track the status if there is no shipment of product within 2 days then there is must have a notification to alert them by email to do a shipment. The shipment date can be fetch from email date but it is possible if I compare :

//MAX(date_shipment = latest date record of shipment in database

if (MAX(date_shipment) - dateNow() >= 2 days )
{
   $update ="update table1 set remarks = 'No shipment received since 2 days ago', status = 'warning'";
   $result = mysql_query($update);
}
else
{ }

But there is problem I thinks because this code is compare with dateNow(). How come if there is new shipment received, still the date comparison code running but not compare with this new shipment date received. I have no idea how to explain and how to start to do this function.

Can someone advise what is the right way to solve this prob? Thanks in advance

5
  • Please show us your code. This is not enough for us to go on. Commented Dec 15, 2014 at 3:47
  • if (MAX(date_shipment) - dateNow() >= 2 days ) this won't parse in PHP. Your update table1 set remarks = 'No shipment received since 2 days ago', status = 'warning' query will update every row of your table since you didn't specify a WHERE clause. Commented Dec 15, 2014 at 3:51
  • date_shipment should be $date_shipment? Is this a date element from the database? Commented Dec 15, 2014 at 3:54
  • @SverriM.Olsen I not yet do the code. still in understanding the process flow Commented Dec 15, 2014 at 3:54
  • But what if the new shipment is received the status warning is still display right when we just compare the latest date_shipment in db with datenow() Commented Dec 15, 2014 at 5:31

2 Answers 2

0

Let's try this code:

$currentDate = getdate();
$anotherDate = MAX(date_shipment); //whatever this is

//this will give sql format to the current date
$year = $currentDate['year'];
$month = $currentDate['mon'];
$day = $currentDate['mday'];
$currentDate = $year.'-'.$month.'-'.$day;

$date1 = date_create($anotherDate); //assuming your date has sql format
$date2 = date_create($currentDate);

$difference = date_diff($date1, $date2);
$difference = str_replace(" days","",$difference->format('%R%a days'));

if ($difference >= 2){
    $update ="update table1 set remarks = 'No shipment received since 2 days ago', status = 'warning'";
    $result = mysql_query($update);
}
else
{ } //I don't get what you want here
Sign up to request clarification or add additional context in comments.

3 Comments

I got this error "Fatal error: Call to undefined function date_create()" when I follow this code. Any idea?
it is like this the function $date=date_create("2013-03-15"); but we have format the date function $currentDate = $year.'-'.$month.'-'.$day;
It turns out that function date_create() exists. Check here: w3schools.com/php/func_date_date_create.asp
0

This seems like what you are trying to do. Do not use mysql anymore, use mysqli.

$dbDate = mysql_query("SELECT `date_shipment` FROM table1");

$addedDate = new DateTime();
$addedDate->modify('+2 day');

if ($dbDate['date_shipment'] >= $addedDate)
{
   $update ="UPDATE table1 SET remarks = 'No shipment received since 2 days ago',
   status = 'warning'";
   $result = mysql_query($update);
}
else
{ }

6 Comments

but I'm using mysql now. The program display this error " Call to undefined function mysqli_query()" when I run this code
I tailored my answer to mysqli, because that is what you should be using. Try it now.
still there is error "Fatal error: Call to undefined function mysqli_query()" when Im using mysqli
You have not updated all your code. Look above, nothing is calling that function. In order to use mysqli, you need to change other code such as the connection.
$addedDate refer to what? it is current date? because the error display "Fatal error: Class 'DateTime' not found". so i need to update DateTime function. It is possible if I change DateTime() to dateNow()
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.