473,385 Members | 1,384 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,385 software developers and data experts.

Calculating week range from specific date - Any functions?

Help,

I am sure this has been asked before but it is difficult to search for.
Given a date, is there a function or a already written script out there that
will allow my to get the previous Monday before the date given?

This is so that given the current date, I can show all events that are
happening for that week. I also will want to do the same for the month. I
know I could go about writing algorithms to calculate this, but I am sure
this is something that has been done numerous times before.

Also is there anywhere out there built an easy to plug in calendar view
function that rather then my user manually entering the dates they want to
select, can just select a particular date?

Kind regards

Dave
Jul 17 '05 #1
6 8528
"Dave Smithz" <SPAM FREE WORLD> wrote in
news:42********@news1.homechoice.co.uk:
Help,

I am sure this has been asked before but it is difficult to search
for. Given a date, is there a function or a already written script out
there that will allow my to get the previous Monday before the date
given?

This is so that given the current date, I can show all events that are
happening for that week. I also will want to do the same for the
month. I know I could go about writing algorithms to calculate this,
but I am sure this is something that has been done numerous times
before.


this is really great:

http://www.phpclasses.org/browse/package/943.html
Jul 17 '05 #2

"Good Man" <he***@letsgo.com> wrote in message
news:Xn************************@216.196.97.131...
this is really great:

http://www.phpclasses.org/browse/package/943.html


Hmmm, did not immediately love it. Spent quite a lot of time getting it and
reading about it, and to be honest it is still quite long winded to achieve
the answer to a question like

What is the date of the Monday before the date I have given you. I still had
to write quite a lot of logic around the available functions to achieve
this. Maybe I'm using it wrong or missed something.

Looks useful if I want to work out roman numerals or moon phase etc.

Jul 17 '05 #3
On Sat, 7 May 2005 11:22:51 +0100, "Dave Smithz" wrote:
http://www.phpclasses.org/browse/package/943.html


Looks useful if I want to work out roman numerals or moon phase etc.


Haha!

To answer your question: no there is no single function to get the
Monday before given date. Try:

$mydate = mktime( 12, 0, 0, $month, $day, $year );
//or: $mydate = strtotime( 'some date string' );
//or get it from mysql_query( 'SELECT UNIXDATE(datefield) FROM table' )

//get weekday with monday==0, sunday==6
$weekday = ((int)date( 'w', $mydate ) + 6 ) % 7;

//get first monday on or before given date
$prevmonday = $mydate - $weekday * 24 * 3600;

//format date
echo 'Monday of this week: '.date( 'l j F Y', $prevmonday );
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #4
On Fri, 06 May 2005 17:44:26 +0100, Dave Smithz wrote:
I am sure this has been asked before but it is difficult to search for.
Given a date, is there a function or a already written script out there that
will allow my to get the previous Monday before the date given?


If $ts is a UNIX timestamp for the date you want to use, the following
should put the right timestamp into $monday:

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

Adam

--
Adam Harvey
Optimiser Pty Ltd

To e-mail: don't make an example out of me!

Jul 17 '05 #5
On Tue, 10 May 2005 16:09:46 +0800, Adam Harvey wrote:
$monday = strtotime('last monday', $ts);


Except that for Mondays, it returns the previous Monday.
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #6
Ewoud Dronkert wrote:
On Tue, 10 May 2005 16:09:46 +0800, Adam Harvey wrote:
$monday = strtotime('last monday', $ts);

Except that for Mondays, it returns the previous Monday.

Just move ahead a day...

$monday = strtotime('last monday', $ts+24*60*60);
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #7

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

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
2
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: -...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
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...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
1
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the...
2
by: planetthoughtful | last post by:
Hi All, I'm building some reports in Acc97 and using a custom calendar form to allow users to pick dates with which to report. I'm wondering if there's an easy way in code to be able to...
0
by: babujigodem | last post by:
Yes i have the function First of all calculate the week number of the desired date and apply the following function function retornarRangoDiasxSemana($anno, $semana) { // Determinar...
1
by: Hetal | last post by:
I am working on Visual Basic 2003 and i had a question about date functions. Is there a way to get the date range for a week based on the combination of 1) Week of the year and 2) Year? I mean, is...
3
Claus Mygind
by: Claus Mygind | last post by:
My date calculation do not seem to work out. I have a list box with a character string value of dates ie: 03/28/2009. I want to create a date range for the week. So I would like to get the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.