Date, beginning of week

Hi all



I'm trying to write a script that works out the day of week, goes back to
previous Monday, then removes a week and sets up 2 timestamps.



EG, if the day was Wednesday 28 Feb 2007 then is would work out that the
Monday was the 26, then remove 7 days to give me my start data and add 6
days to give me my end date. So for Wednesday 28 Feb 2007 I should end up
with Mon 19th Feb to Sun 26th Feb



I have hit a problem, the way I am working it out all goes wrong at the
beginning of the month, bacuse of this



if ($daynum > 1) {

$d = $d - $daynum + 1;

}



Any ideas how I can do this?



$d = date("d"); // 01 to 31

$m = date("m"); // 01 through 12

$y = date("Y"); // 2006

$daynum = date("w");

if ($daynum > 1) {

$d = $d - $daynum + 1;

}

$d = $d - 7;

$startdate = mktime(0, 0, 0, $m,$d,$y);

$weeknumber = date("W", $startdate); // eg 6

$d = $d+6;

$m = date("m");

$y = date("Y");

$enddate = mktime(23, 59, 59, $m,$d,$y);



$realstartdate = date("D j M y H:i:s a", $startdate);

$realenddate = date("D j M y H:i:s a", $enddate);





Cheers

Brian





------------------------------------------------------------ --------------------

I am using the free version of SPAMfighter for private users.
It has removed 168 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Brian [ Fr, 02 März 2007 15:05 ] [ ID #1645775 ]

Re: Date, beginning of week

| I'm trying to write a script that works out the day of week, goes back to
| previous Monday, then removes a week and sets up 2 timestamps.

$today = strtotime(date('m/d/Y') . ' 00:00');
$monday = strtotime('last monday', $today);
$monday = strtotime('last monday', $monday);
$sunday = strtotime('next sunday', $monday);

print_r(array(date('D j M y H:i:s a', $monday), date('D j M y H:i:s a',
$sunday)));


| EG, if the day was Wednesday 28 Feb 2007 then is would work out that the
| Monday was the 26, then remove 7 days to give me my start data and add 6
| days to give me my end date. So for Wednesday 28 Feb 2007 I should end up
| with Mon 19th Feb to Sun 26th Feb

you could also do date math with the strtotime function...such as,
strtotime('-7 days', $monday)...i did not do that here as you seem to alway
be looking for the start and end of the week.

hth...let me know how it works. i just wrote it here and haven't debugged
it, so there may be syntax problems.

me
Steve [ Fr, 02 März 2007 15:25 ] [ ID #1645777 ]

Re: Date, beginning of week

Brian <brian_no_spam [at] nrwp.co.uk> wrote:
> I'm trying to write a script that works out the day of week, goes back=
to
> previous Monday, then removes a week and sets up 2 timestamps.

Does it go back to the previous Monday if the current day is a Monday?

> EG, if the day was Wednesday 28 Feb 2007 then is would work out that t=
he
> Monday was the 26, then remove 7 days to give me my start data and add=
6
> days to give me my end date. So for Wednesday 28 Feb 2007 I should end=
up
> with Mon 19th Feb to Sun 26th Feb

<?php
$date =3D ; //some timestamp

//strftime('%w') gives day of the week 0-6
$day =3D intval(strftime('%w',$date));

//change to < if the same monday is OK)
$day_diff =3D (($day =3D=3D 0) ? 6 : $day - 1)*(60*60*24);

$start =3D $date - (60*60*24*7) - $day_diff;
$end =3D $start + (60*60*24*6);
?>
-- =

Rik Wasmus
Rik [ Fr, 02 März 2007 15:35 ] [ ID #1645778 ]

Re: Date, beginning of week

Brian wrote:
> Hi all
>
>
>
> I'm trying to write a script that works out the day of week, goes back to
> previous Monday, then removes a week and sets up 2 timestamps.
>
>
>
> EG, if the day was Wednesday 28 Feb 2007 then is would work out that the
> Monday was the 26, then remove 7 days to give me my start data and add 6
> days to give me my end date. So for Wednesday 28 Feb 2007 I should end up
> with Mon 19th Feb to Sun 26th Feb
>
>
>
> I have hit a problem, the way I am working it out all goes wrong at the
> beginning of the month, bacuse of this

Here is how you get the unixtime for Monday (00:00:00) and Sunday (23:59:59)

/* How many days today is from Monday */
$frommonday=date('N')-1;

/* Monday. we use (todays month) and (todays day minus days from Monday) */
$monday=mktime(0,0,0,date('m'),date('j')-$frommonday);

/* Sonday, wse use (todays month) and (todays day plus max days to Sunday
minus days from Monday)*/
$sunday=mktime(23,59,59,date('m'),date('j')+6-$frommonday);

So, do what you want with $monday and $sunday.

--

//Aho
Shion [ Fr, 02 März 2007 15:38 ] [ ID #1645779 ]

Re: Date, beginning of week

"Steve" <no.one [at] example.com> wrote in message
news:nvWFh.6$0P1.0 [at] newsfe06.lga...
|| I'm trying to write a script that works out the day of week, goes back to
|| previous Monday, then removes a week and sets up 2 timestamps.
|
| $today = strtotime(date('m/d/Y') . ' 00:00');
| $monday = strtotime('last monday', $today);
| $monday = strtotime('last monday', $monday);
| $sunday = strtotime('next sunday', $monday);
|
| print_r(array(date('D j M y H:i:s a', $monday), date('D j M y H:i:s a',
| $sunday)));

rik brought up a good point. if $today is monday, do you want the monday 2
weeks ago or just one. while i love date math, i think this may be more
understandable for the novice:

$today = strtotime(date('m/d/Y') . ' 00:00');
$monday = strtotime('last monday', $today);
if (intval(strftime('%w', $monday)) != 0)
{
$monday = strtotime('last monday', $monday);
}
$sunday = strtotime('next sunday', $monday);
Steve [ Fr, 02 März 2007 15:46 ] [ ID #1645780 ]

Re: Date, beginning of week

J.O. Aho wrote:
> Brian wrote:
>> Hi all
>>
>>
>>
>> I'm trying to write a script that works out the day of week, goes back
>> to previous Monday, then removes a week and sets up 2 timestamps.
>>
>>
>>
>> EG, if the day was Wednesday 28 Feb 2007 then is would work out that
>> the Monday was the 26, then remove 7 days to give me my start data and
>> add 6 days to give me my end date. So for Wednesday 28 Feb 2007 I
>> should end up with Mon 19th Feb to Sun 26th Feb
>>
>>
>>
>> I have hit a problem, the way I am working it out all goes wrong at
>> the beginning of the month, bacuse of this
>
> Here is how you get the unixtime for Monday (00:00:00) and Sunday
> (23:59:59)

I missed it was supposed to be a week earlier, it's just subtract 7 more days
from $frommonday.
> /* How many days today is from Monday */
> $frommonday=date('N')-1;

$frommonday=date('N')-8;

> /* Monday. we use (todays month) and (todays day minus days from Monday) */
> $monday=mktime(0,0,0,date('m'),date('j')-$frommonday);
>
> /* Sonday, wse use (todays month) and (todays day plus max days to
> Sunday minus days from Monday)*/
> $sunday=mktime(23,59,59,date('m'),date('j')+6-$frommonday);
>
> So, do what you want with $monday and $sunday.

--

//Aho
Shion [ Fr, 02 März 2007 15:57 ] [ ID #1645781 ]

Re: Date, beginning of week

"Steve" <no.one [at] example.com> wrote in message
news:KOWFh.11$0P1.5 [at] newsfe06.lga...
|
| "Steve" <no.one [at] example.com> wrote in message
| news:nvWFh.6$0P1.0 [at] newsfe06.lga...
||| I'm trying to write a script that works out the day of week, goes back
to
||| previous Monday, then removes a week and sets up 2 timestamps.
||
|| $today = strtotime(date('m/d/Y') . ' 00:00');
|| $monday = strtotime('last monday', $today);
|| $monday = strtotime('last monday', $monday);
|| $sunday = strtotime('next sunday', $monday);
||
|| print_r(array(date('D j M y H:i:s a', $monday), date('D j M y H:i:s a',
|| $sunday)));
|
| rik brought up a good point. if $today is monday, do you want the monday 2
| weeks ago or just one. while i love date math, i think this may be more
| understandable for the novice:
|
| $today = strtotime(date('m/d/Y') . ' 00:00');
| $monday = strtotime('last monday', $today);
| if (intval(strftime('%w', $monday)) != 0)

lol...it's still early for me. change that to:

if (intval(strftime('%w', $today)) != 0)
Steve [ Fr, 02 März 2007 15:57 ] [ ID #1645782 ]

Re: Date, beginning of week

Hi All

I should have made this a little clear, I need to end up with 2 timestampes
and not the formatted time, $realstartdate and $realenddate are just
for visuals

thanks for all your replies, now just got to work out want they all mean :)

Brian


"Brian" <brian_no_spam [at] nrwp.co.uk> wrote in message
news:6bWFh.32587$s47.8173 [at] newsfe4-gui.ntli.net...
>
>
> Hi all
>
>
>
> I'm trying to write a script that works out the day of week, goes back to
> previous Monday, then removes a week and sets up 2 timestamps.
>
>
>
> EG, if the day was Wednesday 28 Feb 2007 then is would work out that the
> Monday was the 26, then remove 7 days to give me my start data and add 6
> days to give me my end date. So for Wednesday 28 Feb 2007 I should end up
> with Mon 19th Feb to Sun 26th Feb
>
>
>
> I have hit a problem, the way I am working it out all goes wrong at the
> beginning of the month, bacuse of this
>
>
>
> if ($daynum > 1) {
>
> $d = $d - $daynum + 1;
>
> }
>
>
>
> Any ideas how I can do this?
>
>
>
> $d = date("d"); // 01 to 31
>
> $m = date("m"); // 01 through 12
>
> $y = date("Y"); // 2006
>
> $daynum = date("w");
>
> if ($daynum > 1) {
>
> $d = $d - $daynum + 1;
>
> }
>
> $d = $d - 7;
>
> $startdate = mktime(0, 0, 0, $m,$d,$y);
>
> $weeknumber = date("W", $startdate); // eg 6
>
> $d = $d+6;
>
> $m = date("m");
>
> $y = date("Y");
>
> $enddate = mktime(23, 59, 59, $m,$d,$y);
>
>
>
> $realstartdate = date("D j M y H:i:s a", $startdate);
>
> $realenddate = date("D j M y H:i:s a", $enddate);
>
>
>
>
>
> Cheers
>
> Brian
>
>
>
>
>
> ------------------------------------------------------------ --------------------
>
> I am using the free version of SPAMfighter for private users.
> It has removed 168 spam emails to date.
> Paying users do not have this message in their emails.
> Try SPAMfighter for free now!
>
>
>

------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 168 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Brian [ Fr, 02 März 2007 16:03 ] [ ID #1645783 ]

Re: Date, beginning of week

"Rik" <luiheidsgoeroe [at] hotmail.com> wrote in message
news:op.tokf4812qnv3q9 [at] misant...
> Does it go back to the previous Monday if the current day is a Monday?

Yes always the week before, so even if it's Monday still go back a week, if
it;s
Wednesday, then go back 1 week and 2 days

I need to end up with 2 timestamps from the priviose week starting on the
monday
at 00:00:00 and ending on the Sunday at 23:59:59

Brian

------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 168 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Brian [ Fr, 02 März 2007 16:12 ] [ ID #1645784 ]

Re: Date, beginning of week

"Brian" <brian_no_spam [at] nrwp.co.uk> wrote in message
news:Q9XFh.41373$Fm2.13741 [at] newsfe1-gui.ntli.net...
|
| "Rik" <luiheidsgoeroe [at] hotmail.com> wrote in message
| news:op.tokf4812qnv3q9 [at] misant...
| > Does it go back to the previous Monday if the current day is a Monday?
|
| Yes always the week before, so even if it's Monday still go back a week,
if
| it;s
| Wednesday, then go back 1 week and 2 days
|
| I need to end up with 2 timestamps from the priviose week starting on the
| monday
| at 00:00:00 and ending on the Sunday at 23:59:59


so whatever today is, get the date of last week's monday. this is the start
date. from there, the following sunday is the end date...right?

$today = strtotime(date('m/d/Y') . ' 00:00');
$monday = strtotime('last monday', $today);

// at this point, $monday is either the monday of the same
// week as $today or, it is the monday of the week prior
// to the week of $today
// find out here:

if (intval(strftime('%w', $today)) != 0)
{
// $today is NOT monday, so we need to get
// last week's monday

$monday = strtotime('last monday', $monday);
}

// either way, sunday is determined by $monday

$sunday = strtotime('next sunday', $monday);

make sense? your start date is now $monday and, your end date is $sunday.

this tries to use text-based to help it be more easily understood. if you
like the brevity of date math, go for it.

hth,

me
Steve [ Fr, 02 März 2007 16:27 ] [ ID #1645785 ]

Re: Date, beginning of week

"Steve" <no.one [at] example.com> wrote in message
news:opXFh.7$Xo3.4 [at] newsfe03.lga...
|
| "Brian" <brian_no_spam [at] nrwp.co.uk> wrote in message
| news:Q9XFh.41373$Fm2.13741 [at] newsfe1-gui.ntli.net...
||
|| "Rik" <luiheidsgoeroe [at] hotmail.com> wrote in message
|| news:op.tokf4812qnv3q9 [at] misant...
|| > Does it go back to the previous Monday if the current day is a Monday?
||
|| Yes always the week before, so even if it's Monday still go back a week,
| if
|| it;s
|| Wednesday, then go back 1 week and 2 days
||
|| I need to end up with 2 timestamps from the priviose week starting on the
|| monday
|| at 00:00:00 and ending on the Sunday at 23:59:59
|
|
| so whatever today is, get the date of last week's monday. this is the
start
| date. from there, the following sunday is the end date...right?
|
| $today = strtotime(date('m/d/Y') . ' 00:00');
| $monday = strtotime('last monday', $today);
|
| // at this point, $monday is either the monday of the same
| // week as $today or, it is the monday of the week prior
| // to the week of $today
| // find out here:
|
| if (intval(strftime('%w', $today)) != 0)
| {
| // $today is NOT monday, so we need to get
| // last week's monday
|
| $monday = strtotime('last monday', $monday);
| }
|
| // either way, sunday is determined by $monday
|
| $sunday = strtotime('next sunday', $monday);

ok...just saw the the end date should be the last second of sunday. add this
as your final line of code:

$sunday = strtotime(date('m/d/Y', $sunday) . ' 24:59:59');
Steve [ Fr, 02 März 2007 16:30 ] [ ID #1645786 ]

Re: Date, beginning of week

Message-ID: <KOWFh.11$0P1.5 [at] newsfe06.lga> from Steve contained the
following:

>while i love date math,

You da man next time I have some to do. It does my head in.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 02 März 2007 16:51 ] [ ID #1645787 ]

Re: Date, beginning of week

"Steve" <no.one [at] example.com> wrote in message
news:0sXFh.8$Xo3.1 [at] newsfe03.lga...
> |
> | $today = strtotime(date('m/d/Y') . ' 00:00');
> | $monday = strtotime('last monday', $today);
> |
> | // at this point, $monday is either the monday of the same
> | // week as $today or, it is the monday of the week prior
> | // to the week of $today
> | // find out here:
> |
> | if (intval(strftime('%w', $today)) != 0)
> | {
> | // $today is NOT monday, so we need to get
> | // last week's monday
> |
> | $monday = strtotime('last monday', $monday);
> | }
> |
> | // either way, sunday is determined by $monday
> |
> | $sunday = strtotime('next sunday', $monday);
>
> ok...just saw the the end date should be the last second of sunday. add
> this
> as your final line of code:
>
> $sunday = strtotime(date('m/d/Y', $sunday) . ' 24:59:59');
>
Hi Steve

Am I missing soothing here, the Monday is correct, but I can't see how you
are working out the Sunday, if I run the script I get the following

Monday = Mon 19 Feb 07 00:00:00 am
Sunday = Mon 19 Feb 07 23:59:59 pm

is should be

Monday = Mon 19 Feb 07 00:00:00 am
Sunday = Sun 25 Feb 07 23:59:59 pm

Sorry to be a pain, I hate dates and timestamps !

today = strtotime(date('m/d/Y') . ' 00:00');
$monday = strtotime('last monday', $today);

// at this point, $monday is either the monday of the same
// week as $today or, it is the monday of the week prior
// to the week of $today
// find out here:

if (intval(strftime('%w', $today)) != 0) {
// $today is NOT monday, so we need to get
// last week's monday
$monday = strtotime('last monday', $monday);
}

// either way, sunday is determined by $monday

$sunday = strtotime(date('m/d/Y', $monday) . ' 23:59:59');

$realstartdate = date("D j M y H:i:s a", $monday);
$realenddate = date("D j M y H:i:s a", $sunday);

Thanks


Brian



------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 173 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Brian [ Fr, 02 März 2007 17:10 ] [ ID #1645788 ]

Re: Date, beginning of week

"Geoff Berrow" <blthecat [at] ckdog.co.uk> wrote in message
news:mvhgu2pmki1oqusomrv0uggqkm2sss0nci [at] 4ax.com...
| Message-ID: <KOWFh.11$0P1.5 [at] newsfe06.lga> from Steve contained the
| following:
|
| >while i love date math,
|
| You da man next time I have some to do. It does my head in.

i'm hardly da man...you've seen the shit i've posted here. now, you, aho,
and rik...that's the story!

i like date math because it forces me to think concisely. it's hard to catch
all the exceptions in a neat and tidy formula...but i like to fish. ;^)

cheers
Steve [ Fr, 02 März 2007 17:10 ] [ ID #1645789 ]

Re: Date, beginning of week

| > ok...just saw the the end date should be the last second of sunday. add
| > this
| > as your final line of code:
| >
| > $sunday = strtotime(date('m/d/Y', $sunday) . ' 24:59:59');

NOTE!!!

'ADD this as your FINAL line of code:'


| Am I missing soothing here, the Monday is correct, but I can't see how you
| are working out the Sunday, if I run the script I get the following

all is well. perhaps i should not give directions, but instead give code.
here's the uncommented, fully-complete code:

$today = strtotime(date('m/d/Y') . ' 00:00');
$monday = strtotime('last monday', $today);
if (intval(strftime('%w', $today)) != 0) {
$monday = strtotime('last monday', $monday);
}
$sunday = strtotime('next sunday', $monday);
$sunday = strtotime(date('m/d/Y', $sunday) . ' 23:59:59');
Steve [ Fr, 02 März 2007 17:19 ] [ ID #1645790 ]

Re: Date, beginning of week

"Steve" <no.one [at] example.com> wrote in message
news:9aYFh.8$ij4.7 [at] newsfe04.lga...

Sorry i didn't undersatnd you mean both lines, MANY MANY MANY thanks
all working :)


> $sunday = strtotime('next sunday', $monday);
> $sunday = strtotime(date('m/d/Y', $sunday) . ' 23:59:59');
>

Brian

------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 173 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Brian [ Fr, 02 März 2007 17:29 ] [ ID #1645792 ]

Re: Date, beginning of week

"Brian" <brian_no_spam [at] nrwp.co.uk> wrote in message
news:khYFh.49640$Da4.7880 [at] newsfe6-gui.ntli.net...
>
> Sorry i didn't undersatnd you mean both lines, MANY MANY MANY thanks
> all working :)
>
>
>> $sunday = strtotime('next sunday', $monday);
>> $sunday = strtotime(date('m/d/Y', $sunday) . ' 23:59:59');
>>

Hi Steve (sorry again)

Spoke to soon, I understand what you are doing (well it think so)
and it should work, but the Sunday is not working

Monday is OK so if i have this right this is what is happening

// get the next sunday after the monday we just set
// using the monday to work this out
$sunday = strtotime('next sunday', $monday);

// set the above sunday time to 23:59:59
$sunday = strtotime(date('m/d/Y', $sunday) . ' 23:59:59');

This should work, but if I run it now I get the correct
Monday (Mon 19 Feb 07, 00:00:00 ) but it keeps
setting next Sundays date (Sun 4 Mar 07, 23:59:59)
instead of 25th Feb.
It seems to be ignoring the fact we am saying work out
the next Sunday from the Monday we set

Below is all the code I am using, am I missing something
again?

Brian

$today = strtotime(date('m/d/Y') . ' 00:00');
$monday = strtotime('last monday', $today);

// at this point, $monday is either the monday of the same
// week as $today or, it is the monday of the week prior
// to the week of $today
// find out here:
if (intval(strftime('%w', $today)) != 0) {
// $today is NOT monday, so we need to get
// last week's monday
$monday = strtotime('last monday', $monday);
}
// either way, sunday is determined by $monday
$sunday = strtotime('next sunday', $monday);
$sunday = strtotime(date('m/d/Y', $sunday) . ' 23:59:59');

// build up some string to view timestamps in real dates
$realstartdate = date("D j M y, H:i:s a", $monday);
$realenddate = date("D j M y, H:i:s a", $sunday);
// print out real dates to make sure dates are correct
echo "Start: $realstartdate ($monday)<br>End: $realenddate ($sunday)
<br>Weeknumber is $weeknumber<br>";

------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 173 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Brian [ Fr, 02 März 2007 18:06 ] [ ID #1645795 ]

Re: Date, beginning of week

J.O. Aho wrote:
> J.O. Aho wrote:
>> Brian wrote:
>>> Hi all
>>>
>>>
>>>
>>> I'm trying to write a script that works out the day of week, goes
>>> back to previous Monday, then removes a week and sets up 2 timestamps.
>>>
>>>
>>>
>>> EG, if the day was Wednesday 28 Feb 2007 then is would work out that
>>> the Monday was the 26, then remove 7 days to give me my start data
>>> and add 6 days to give me my end date. So for Wednesday 28 Feb 2007 I
>>> should end up with Mon 19th Feb to Sun 26th Feb
>>>
>>>
>>>
>>> I have hit a problem, the way I am working it out all goes wrong at
>>> the beginning of the month, bacuse of this
>>
>> Here is how you get the unixtime for Monday (00:00:00) and Sunday
>> (23:59:59)
>
> I missed it was supposed to be a week earlier, it's just subtract 7 more
> days from $frommonday.

Steven shouldn't have praised me that much, he prolly wouldn't if he noticed
that I mixed up the signs and I shouldn't have subtracted, but added 7 more
days to the $frommonday.

>> /* How many days today is from Monday */
>> $frommonday=date('N')-1;

$frommonday=date('N')+6;

>> /* Monday. we use (todays month) and (todays day minus days from
>> Monday) */
>> $monday=mktime(0,0,0,date('m'),date('j')-$frommonday);
>>
>> /* Sonday, wse use (todays month) and (todays day plus max days to
>> Sunday minus days from Monday)*/
>> $sunday=mktime(23,59,59,date('m'),date('j')+6-$frommonday);
>>
>> So, do what you want with $monday and $sunday.



--

//Aho
Shion [ Fr, 02 März 2007 18:26 ] [ ID #1645797 ]

Re: Date, beginning of week

"J.O. Aho" <user [at] example.net> wrote in message
news:54r52qF227se8U1 [at] mid.individual.net...
| J.O. Aho wrote:
| > J.O. Aho wrote:
| >> Brian wrote:
| >>> Hi all
| >>>
| >>>
| >>>
| >>> I'm trying to write a script that works out the day of week, goes
| >>> back to previous Monday, then removes a week and sets up 2 timestamps.
| >>>
| >>>
| >>>
| >>> EG, if the day was Wednesday 28 Feb 2007 then is would work out that
| >>> the Monday was the 26, then remove 7 days to give me my start data
| >>> and add 6 days to give me my end date. So for Wednesday 28 Feb 2007 I
| >>> should end up with Mon 19th Feb to Sun 26th Feb
| >>>
| >>>
| >>>
| >>> I have hit a problem, the way I am working it out all goes wrong at
| >>> the beginning of the month, bacuse of this
| >>
| >> Here is how you get the unixtime for Monday (00:00:00) and Sunday
| >> (23:59:59)
| >
| > I missed it was supposed to be a week earlier, it's just subtract 7 more
| > days from $frommonday.
|
| Steven shouldn't have praised me that much, he prolly wouldn't if he
noticed
| that I mixed up the signs and I shouldn't have subtracted, but added 7
more
| days to the $frommonday.

sure i would have (and do)...and, i did notice. that's just an oversite.
were there money on that, i'd have been pissed. ;^)

as it is, i'm more interested in seeing the different approaches people
take. yours is 3 lines of code, nice and concise. i opted for six
non-commented lines hoping the 'last monday' textual method would both
return the values expected and serve as commantary at the same time.

i like the way you've done it! the good news is, there are always more cats
than the almost infinite number of ways one could skin them. ;^)

cheers.
Steve [ Fr, 02 März 2007 18:37 ] [ ID #1645798 ]

Re: Date, beginning of week

Steve wrote:

> as it is, i'm more interested in seeing the different approaches people
> take. yours is 3 lines of code, nice and concise. i opted for six
> non-commented lines hoping the 'last monday' textual method would both
> return the values expected and serve as commantary at the same time.
> i like the way you've done it!


Yes, and we had three different ways to do things in a quite short timespan.

I agree with you about your method, myself I always forget the strtotime() and
how to use it with ease and it has been that I have reinvented the wheel with
making my own version to take a date in text format parse it and then feed it
to mktime() to get the unixtime.



> the good news is, there are always more cats
> than the almost infinite number of ways one could skin them. ;^)

It's both good and bad, as not all the solutions are good ones, as the one I
thought of before I posted my code, it's been a lot longer and really a pita
to debug.


--

//Aho
Shion [ Fr, 02 März 2007 19:54 ] [ ID #1645799 ]
PHP » alt.php » Date, beginning of week

Vorheriges Thema: textarea fields --> export to ms word --> word is stretch
Nächstes Thema: Which php debugger do you use?