View Full Version : date concatenation problem

01-14-2008, 03:19 AM
hi friends ,

I am concatenating the day and month of the year to change the delivery day in case of public holiday

the code i am using is

$pbDate2 = date('d')+$i;
$pbMon2 = date('m');

if($pbDate2 > 31)
{ $pbDate2 = $pbDate2 - 31;
$pbMon2 = $pbMon2 + 1;
if($pbMon2 >12)
$pbMon2 = $pbMon2-12 ;
$pbDate2 = $pbDate2.$pbMon2;

The problem is e.g

if my delivery day start fro 28 dec and gos to 3 january and there is holiday on 2 jan

then pbdate2 variable will return "21"
2 for day and 1 for month

The problem occured when date is 1 jan , then month variable is returned as 01 and the variable becomes 201.

This problem occured yhis year and there are customers who placed orders for 2 januray on 1 january. I check from december month but not on 1 january.

Any simple solution?

01-14-2008, 04:16 AM
I don't quite understand what you are doing, but once you determine if a holiday exists within a time period, you can simply run an strtotime and add a day to your current timestamp values. This assumes you use a timestamp of course, otherwise you just do some date format and comparisons between the two.
I assume the idea is that you select items to purchase or whatever, and select a delivery type which has a different time for delivery, say 5 days. If within the 5 day period you have a holiday, it ends up being 6 days, am I right? If so, this idea will work, just determine if a holiday exists (no I don't want to write that up on the fly ;)), then take your original delivery date and add a +1 on an strtotime to it, should work like a charm (I used that on a project to cheap out on a two week period so I didn't need to error check it off the form).

$newDate = strtotime("+1 day", $originalDeliveryDate);

is an example of what to do. Check the site for strtotime, there is a link to GNU standards for what the date format in english can look like, there are a lot of options. Frankly, the date() functionality of PHP impresses me far more than most of the other languages that I've used...