473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

strtotime - Monday of current week

I am trying to output Monday of the current week i.e. if Monday is the
8th I want to display 'Monday 8th' for any date between Monday 8-14th.

I would appreciate any help, the code below is heading in the right
direction but doesn't quite give me the results I am looking for.

$givenday = mktime(0,0,0,10,08,2007);
$Monday = strtotime("Monday this week",$givenday);
echo date("j M Y H:i:s", $Monday);

Cheers,

Chris

Oct 11 '07 #1
5 13696
In our last episode,
<11**********************@g4g2000hsf.googlegroups. com>,
the lovely and talented Chris
broadcast on comp.lang.php:
I am trying to output Monday of the current week i.e. if Monday is the
8th I want to display 'Monday 8th' for any date between Monday 8-14th.
I would appreciate any help, the code below is heading in the right
direction but doesn't quite give me the results I am looking for.
$givenday = mktime(0,0,0,10,08,2007);
$Monday = strtotime("Monday this week",$givenday);
echo date("j M Y H:i:s", $Monday);
Cheers,
Chris
This seems to work for me.

php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
strtotime('Sunday')));"

You want the Monday previous to next Sunday.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 466 days to go.
What do you do when you're debranded?
Oct 11 '07 #2
<comp.lang.php>
<Chris>
<Thu, 11 Oct 2007 15:05:04 -0700>
<11**********************@g4g2000hsf.googlegroups. com>
I am trying to output Monday of the current week i.e. if Monday is the
8th I want to display 'Monday 8th' for any date between Monday 8-14th.

I would appreciate any help, the code below is heading in the right
direction but doesn't quite give me the results I am looking for.

$givenday = mktime(0,0,0,10,08,2007);
$Monday = strtotime("Monday this week",$givenday);
echo date("j M Y H:i:s", $Monday);
<?php

$less=0;

$loopy=1;
while ($loopy<8)
{
$temp1=date("l dS",time()-$less);
$temp2=date("l dS M Y H:i:s",time()-$less);
$wsx=" $temp1 "; $qaz=strpos($wsx,"Monday"); if ($qaz==true) {break;}
$less=$less+86400;
$loopy=$loopy+1;
}

print "temp1 = $temp1 <br>";
print "temp2 = $temp2 <br>";

?>
--
www.vhit.co.uk
www.jpgimage.co.uk
www.phpwhois.co.uk
www.cannabiswindow.co.uk
Oct 11 '07 #3
On Oct 11, 11:29 pm, Lars Eighner <use...@larseighner.comwrote:
In our last episode,
<1192140304.180826.282...@g4g2000hsf.googlegroups. com>,
the lovely and talented Chris
broadcast on comp.lang.php:
I am trying to output Monday of the current week i.e. if Monday is the
8th I want to display 'Monday 8th' for any date between Monday 8-14th.
I would appreciate any help, the code below is heading in the right
direction but doesn't quite give me the results I am looking for.
$givenday = mktime(0,0,0,10,08,2007);
$Monday = strtotime("Monday this week",$givenday);
echo date("j M Y H:i:s", $Monday);
Cheers,
Chris

This seems to work for me.

php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
strtotime('Sunday')));"

You want the Monday previous to next Sunday.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 466 days to go.
What do you do when you're debranded?
Cheers Lars!

I wanted a link to show this monday, then the next etc. Your code
helped, will continue to build on it.

$monday = date('j M Y', strtotime('last Monday',
strtotime('Sunday')));
$unixtime_monday = strtotime($monday);
$next_monday = date('j M Y', strtotime('+1 week', $unixtime_monday));

Chris

Oct 14 '07 #4
On Sun, 14 Oct 2007 21:24:24 +0200, Chris <ma*********@googlemail.com
wrote:
On Oct 11, 11:29 pm, Lars Eighner <use...@larseighner.comwrote:
>In our last episode,
<1192140304.180826.282...@g4g2000hsf.googlegroups .com>,
the lovely and talented Chris
broadcast on comp.lang.php:
I am trying to output Monday of the current week i.e. if Monday is the
8th I want to display 'Monday 8th' for any date between Monday 8-14th.
I would appreciate any help, the code below is heading in the right
direction but doesn't quite give me the results I am looking for.
$givenday = mktime(0,0,0,10,08,2007);
$Monday = strtotime("Monday this week",$givenday);
echo date("j M Y H:i:s", $Monday);
Cheers,
Chris

This seems to work for me.

php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
strtotime('Sunday')));"

You want the Monday previous to next Sunday.

--
Lars Eighner <http://larseighner.com/
<http://myspace.com/larseighner>
Countdown: 466 days to go.
What do you do when you're debranded?

Cheers Lars!

I wanted a link to show this monday, then the next etc. Your code
helped, will continue to build on it.

$monday = date('j M Y', strtotime('last Monday',
strtotime('Sunday')));
$unixtime_monday = strtotime($monday);

Euhm, what am I missing?

$monday = date('j M Y', strtotime('last Monday',strtotime('Sunday')));
$unixtime_monday = strtotime($monday);

Would be equal to:

$unixtime_monday = strtotime('last Monday',strtotime('Sunday'));

is it not?
--
Rik Wasmus
Oct 14 '07 #5
In our last episode, <11**********************@e9g2000prf.googlegroups. com>,
the lovely and talented Chris broadcast on comp.lang.php:
On Oct 11, 11:29 pm, Lars Eighner <use...@larseighner.comwrote:
>In our last episode,
<1192140304.180826.282...@g4g2000hsf.googlegroups .com>,
the lovely and talented Chris
broadcast on comp.lang.php:
I am trying to output Monday of the current week i.e. if Monday is the
8th I want to display 'Monday 8th' for any date between Monday 8-14th.
I would appreciate any help, the code below is heading in the right
direction but doesn't quite give me the results I am looking for.
$givenday = mktime(0,0,0,10,08,2007);
$Monday = strtotime("Monday this week",$givenday);
echo date("j M Y H:i:s", $Monday);
Cheers,
Chris

This seems to work for me.

php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
strtotime('Sunday')));"

You want the Monday previous to next Sunday.
Cheers Lars!
I wanted a link to show this monday, then the next etc. Your code
helped, will continue to build on it.
$monday = date('j M Y', strtotime('last Monday',
strtotime('Sunday')));
$unixtime_monday = strtotime($monday);
$next_monday = date('j M Y', strtotime('+1 week', $unixtime_monday));
Yes, but php strtotime already knows 'next Monday':

Sun Oct 14 15:33:54 bash3.2:ttyp0:lars
debranded~$php -r "echo date('j M Y',strtotime('next Monday'));"
15 Oct 2007

(Yes, it is broken if your php is older than 4.4.0)

The problem part of your original problem was that strtotime doesn't know
something like "Monday of this week". The difficulty of implementing that
in the strtotime function would be that people would have different
understandings of what they mean by 'this week.' For example, your problem
involves the work week (of which Sunday is the last day). Most Western
calendars use a week that ends on Saturday. You might well consider Jan. 1
to be the first day of the first week.
And it has been mentioned that:
$monday = date('j M Y', strtotime('last Monday',
strtotime('Sunday')));
$unixtime_monday = strtotime($monday);
is the same as
$unixtime_monday = strtotime('last Monday', strtotime('Sunday')));
There is no point in going string to time and back.

So even if you have old php (or want to be backwards compatible with
broken versions)

$next_monday = date('j M Y', strtotime('+1 week',
strtotime('last Monday', strtotime('Sunday'))));

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 463 days to go.
What do you do when you're debranded?
Oct 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
4
by: GregginOttawa | last post by:
I've been Googling and reading for 5 days now trying to figure out how to write a query that selects records with dates in the current week (Sun to Sat). You'd think it would be remarkably simple...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
1
by: kennyscripts | last post by:
Hi Friends...... How to get the current month and current week in vb.net 2003 Can view the month textbox details and can only enter the week detail. How to get? Anybody knows give the answer....
5
by: Aljosa Mohorovic | last post by:
i use this to find out current week and total number of weeks for current year: now = datetime.now() weeks_in_year = int(date(now.year, 12, 31).strftime("%W")) current_week = int(date(now.year,...
7
by: anu | last post by:
Please let me know how I can get the starting date of the current week in PHP.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.