Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

date() function help


Guest

Recommended Posts

Hello - I am writing a little hack but am having problems with something. I am pulling the datetime from last_modified, date_available from product_info then to convert it to a day. For example, January 1, or 2004 or 2005 is day 1. December 31 is 365. Any help would be appreciate. Below is the script:

====================

 

$time = abs( date(z, $product_info['products_date_available']) - date(z) );

 

if ( tep_date_long($product_info['products_date_available']) < date('Y-m-d H:i:s')) {

// product_quantity > 0 and have products availabe - ready to ship

echo 'Availability: ' . $product_quantity . ' Usually ships within 1 working day' . $last_modified;

 

} else {

// this logic only works if you update products_date_available often

 

echo 'Availability: ' . $product_quantity . ' Usually ships in ';

if ( $time > 1 ){

echo $time . ' working days' . $last_modified;

} else {

echo $time . ' working day' . $last_modified;

}

 

===================

 

For some reason I am getting the number 135 for date(z, $product_info['products_date_available']) where products_date_available is Feb 22, 2004.

 

Thanks

Link to comment
Share on other sites

this should do it for you

 

$time = (date('z', strtotime($product_info['products_date_available'])) - date('z'));

if ($time <= 1) {
?// product_quantity > 0 and have products availabe - ready to ship
?echo 'Availability: ' . $product_quantity . ' Usually ships within 1 working day' . $last_modified;
} else {
?// this logic only works if you update products_date_available often 
?echo 'Availability: ' . $product_quantity . ' Usually ships in ' . $time . ' working days' . $last_modified;
}

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

just realized that does not take into account years... so going from say Dec 22nd, 2004 to a product available Jan 3rd, 2005, that will return a negative number as the days and say it will ship within 1 day.

 

This will take into account difference in years and with this code, the above example would show "usually ships in 10 days"

$time = round((strtotime($product_info['products_date_available']) - time())/86400);

if ($time <= 1) {
 // product_quantity > 0 and have products availabe - ready to ship
 echo 'Availability: ' . $product_quantity . ' Usually ships within 1 working day' . $last_modified;
} else {
 // this logic only works if you update products_date_available often 
 echo 'Availability: ' . $product_quantity . ' Usually ships in ' . $time . ' working days' . $last_modified;
}

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...