473,803 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP! How to Get Date this Sunday and this Monday

Hello,

Today is Thursday, August 18, 2004. I would like to have a variable
that stores the date this coming Sunday (even if today happened to be
Sunday) in YYY-MM-DD format. I also need a variable that will store
the date this past Monday (even if today happens to be Monday) also in
YYY-MM-DD format.

So, the end result is that, for this week (today is 2004-08-18) I
would have the following two variables:

$this_sunday = 2004-08-21 // This coming Sunday
$this_monday = 2004-08-14 // This past Monday

Thank you very much in advance for any help!

- Eric
Jul 17 '05 #1
5 3213

Well, you'll probably have to ask a girl out for each day.

-d

Jul 17 '05 #2
>Today is Thursday, August 18, 2004. I would like to have a variable

In my world, August 18, 2004 is a WEDNESDAY.
that stores the date this coming Sunday (even if today happened to be
Sunday) in YYY-MM-DD format.
This format has a severe Y1K problem.
I also need a variable that will store
the date this past Monday (even if today happens to be Monday) also in
YYY-MM-DD format.
This format still has a severe Y1K problem.
So, the end result is that, for this week (today is 2004-08-18) I
would have the following two variables:

$this_sunday = 2004-08-21 // This coming Sunday Um, the 21st is a SATURDAY.$this_monday = 2004-08-14 // This past Monday

Um, the 14th is a SATURDAY.

date('w') is the current weekday (0-6).

$x = (0 - date('w')) % 7;
is the number of days you need to add to the current date to
get to next Sunday. (Assuming that if today IS Sunday, you
want today). 0=Sunday If today is Thursday, that's (0-4)%7,
which is 3 days to add.

$x = (date('w') - 1) % 7;
is the number of days you need to subtract from the current
date to get to last Monday. (Assuming that if today IS Monday,
you want today.) 1=Monday If today is Thursday, that's (4-1)%7,
which is 3 days to subtract.

date('Y-m-d', time() + $x*24*60*60)
is the date $x days before (if $x is negative) or after
today in the format you want above. WARNING: there will
be glitches in this around daylight savings time transitions.
I think date('Y-m-d', mktime(0, 0, 0, date('m)', date('d')+$x,
date('Y'))) works better for this (UNIX mktime() allows you
to feed it things like March -1, 2004 and end up with
2004-02-29. I'm not sure that there can't be glitches in
this due to leap seconds.

Gordon L. Burditt
Jul 17 '05 #3
"Eric Linders" <el********@hot mail.com> wrote in message
news:49******** *************** ***@posting.goo gle.com...
Today is Thursday, August 18, 2004. I would like to have a variable
that stores the date this coming Sunday (even if today happened to be
Sunday) in YYY-MM-DD format. I also need a variable that will store
the date this past Monday (even if today happens to be Monday) also in
YYY-MM-DD format.

So, the end result is that, for this week (today is 2004-08-18) I
would have the following two variables:

$this_sunday = 2004-08-21 // This coming Sunday
$this_monday = 2004-08-14 // This past Monday


Actually, this Sunday is the 22nd and Monday was the 16th, so you're going
to have a hard time getting a well-written function to return those values.
:)

<?PHP

$today = unixtojd();

$this_sunday = $today + (7 - jddayofweek($to day)) % 7;
$last_monday = $today - (jddayofweek($t oday) + 6) % 7;

print "Today is " . jdtogregorian($ today) . ".\n";
print "This Sunday is " . jdtogregorian($ this_sunday) . ".\n";
print "Last Monday is " . jdtogregorian($ last_monday) . ".\n";

?>

I'll leave it to you to convert these to yyyy-mm-dd.

Steve
--
Steven C. Gallafent - The Computer Guy, Inc.
st***@compguy.c om - http://www.compguy.com/
Jul 17 '05 #4
Eric Linders wrote:
Hello,

Today is Thursday, August 18, 2004. I would like to have a variable
that stores the date this coming Sunday (even if today happened to be
Sunday) in YYY-MM-DD format. I also need a variable that will store
the date this past Monday (even if today happens to be Monday) also in
YYY-MM-DD format.

So, the end result is that, for this week (today is 2004-08-18) I
would have the following two variables:

$this_sunday = 2004-08-21 // This coming Sunday
$this_monday = 2004-08-14 // This past Monday

Thank you very much in advance for any help!

- Eric


Ok now after u read the above 3 posts here is the PROPER way to do it,
people really should read the php manual.

if (date("l") != "Sunday") // Is today Sunday?
$this_sunday = date("Y-m-d", strtotime("next Sunday")); // No
else
$this_sunday = date("Y-m-d"); // Yes
if (date("l") != "Monday") // Is today Monday?
$this_monday = date("Y-m-d", strtotime("last Monday")); // No
else
$this_monday = date("Y-m-d"); // Yes

And there you have it.

Although the dates you get from this won't match the dates in your
world, you seem to live in a very different timezone.

Jul 17 '05 #5
"Justin Wyer" <ju****@isogo.c o.za> wrote in message
news:cg******** **@ctb-nnrp2.saix.net. ..
Ok now after u read the above 3 posts here is the PROPER way to do it,
people really should read the php manual.


I suggest that should be corrected to "here is A proper way to do it." There
is more than one way to skin this cat. Any of the approaches suggested will
work just fine. Pick your favorite.

Don't forget to read the docs for strtotime so that you are aware of
differences in how older versions of PHP handle this.

Steve
--
Steven C. Gallafent - The Computer Guy, Inc.
st***@compguy.c om - http://www.compguy.com/
Jul 17 '05 #6

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

Similar topics

6
2669
by: Edward King | last post by:
Hi! I am trying to achieve the following: I have a number of help pages (in the format help_nn.php where nn=helpid). I want to be able to open a particular help page by calling the function gethelp(nn) where nn is the helpid. The function is contained in a header file called funcs.inc that each page
11
2894
by: Helmut Jarausch | last post by:
Hi, entering help('rstrip') or help('ljust') into IDLE's shell window I only get no Python documentation found ...
0
2035
by: Tim21 | last post by:
OK, im miserable :)) so.. help'd b highly appreciated. Situation: Win XP aplication server RUNTIME (stored fmx files along with the ..hlp files) Fmx's generated and compiled on development machine (Win2003 Advanced Server), also place of generation of HLP files (using HCW-Help Workshop Compiler)) Problem: When trying to call help file from module (fmx) (ON runtime machine) by pressing F1 (help key),. system seems not to react at all....
6
4359
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
6
3028
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect an html authoring tool to help you accomplish? 2. What do you expect from online help for a html authoring tool? 3. What audience do you think a freeware html authoring tool is directed towards?
3
3369
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
2
2554
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
5
1765
by: dixie | last post by:
I was wondering if there is a way of doing a simple help system with either viewing a page in a browser or looking at a definite page in a .pdf file when a help button was pushed on an Access application form. I understand there are other ways of doing help files, but are these possible, what is the easiest and how much work is it? dixie
5
3388
by: Steve Teeples | last post by:
Can someone point me to a document that clearly identifies the steps of creating a good help system for an application? I have a test tool that I'd like to add help to so that others will know how to use it. -- Steve
8
3238
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10292
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9121
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.