Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Date Calculation Problem w/ mktime()
October 17, 2004, 12:24 am
rate this thread
I am having a problem with calculating a date. What I am looking to do
is get the date of Sunday of this week, then use mktime() to find out
other days in the past by subtracting days.
In the code below, today is Saturday, October 16, 2004, this week's
Sunday is 2004-10-17. I successfully get that.
But, when I try to subtract 7 days using mktime(), I instead of getting
2004-10-10, I get 1969-12-31.
I have looked through php.net/mktime and searched some example via
Google, but I stuck. Any help would be greatly appreciated.
$today = unixtojd();
// GET THIS WEEK'S SUNDAY
$this_sunday = $today + (7 - jddayofweek($today)) % 7;
$current_sunday = jdtogregorian($this_sunday);
$this_sundays_parts = explode("/",$current_sunday);
$cur_sunday = $this_sundays_parts . "-" . $this_sundays_parts .
"-" . $this_sundays_parts;
// GET LAST WEEK'S SUNDAY
$last_sunday = date("Y-m-d", mktime(0, 0, 0,
// PRINT OUT THE DATES
print "This Sunday is " . $cur_sunday . "<BR>";
print "Last Sunday was " . $last_sunday . "<BR>";
Thanks for any help!
- Janwillem Borleffs
October 17, 2004, 6:50 pm