Get date based on weekday? – PHP

  php

Q(Question):

Hello,

I have this:

Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
do is to associate days with its current week dates, for example:

Mon (05.01.2004); Tue (06.01.2004); and so on.

TNX

A(Answer):

"dr. zoidberg" <so*****@14.u7.da.ru> wrote in message news:<G7*****************@ns45.bih.net.ba>…

Hello,

I have this:

Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
do is to associate days with its current week dates, for example:

Mon (05.01.2004); Tue (06.01.2004); and so on.

TNX

I’m not quite sure what you’re trying to accomplish, but you could
always use the date() function.

A(Answer):

mjacob wrote:

"dr. zoidberg" <so*****@14.u7.da.ru>

Hello,

I have this:

Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
do is to associate days with its current week dates, for example:

Mon (05.01.2004); Tue (06.01.2004); and so on.

TNX

I’m not quite sure what you’re trying to accomplish, but you could
always use the date() function.

I’m trying do display weekdays with dates, monday to sunday, but only
for current week, something like small calendar.

A(Answer):

dr. zoidberg wrote:

I’m trying do display weekdays with dates, monday to sunday, but only
for current week, something like small calendar.

<?php
$wd_arr = array(‘Mo ‘, ‘Tu ‘, ‘We ‘, ‘Th ‘, ‘Fr ‘, ‘Sa ‘, ‘Su ‘);
$monday = mktime(0, 0, 0, // hour, minute, second
(int)date(‘m’), // month
(int)date(‘d’)+(1-(int)date(‘w’)), // day (can be negative!)
(int)date(‘Y’)); // year

for ($n=0; $n<7; $n++) {
echo $wd_arr[$n], date(‘Y-m-d’, $monday+$n*60*60*24), "<br/>\n";
}
?>

–= my mail box only accepts =–
–= Content-Type: text/plain =–
–= Size below 10001 bytes =–

A(Answer):

dr. zoidberg schrieb:

mjacob wrote:

"dr. zoidberg" <so*****@14.u7.da.ru>

Hello,

I have this:

Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
do is to associate days with its current week dates, for example:

Mon (05.01.2004); Tue (06.01.2004); and so on.

TNX

I’m not quite sure what you’re trying to accomplish, but you could
always use the date() function.

I’m trying do display weekdays with dates, monday to sunday, but only
for current week, something like small calendar.

Hi mjacob,

i hope this code snippet will help you. I just wrote it down in this
mail, maybe some things do not work instantly but it should at least
show you the way:
// CODE START
switch($weekday) // $weekday should contain "Sun" or "Mon" and so on
{
case "Sun":
$weekdaynr = 0; // assign a nr representing the weekday
break;
case "Mon":
$weekdaynr = 1;
break;

// … and so on …

}

$todaynr = date("w"); // assign the today weekday
$day_diff = $todaynr – $weekdaynr; // get the difference in days
$sec_diff = $daydiff * 24 * 60 * 60; // get the difference in seconds
$target_date = mktime() – $sec_diff; // actual timestamp – difference
echo date ("D (d.M.Y)", $target_date); // output newly formatted date
// CODE END

you can also use strftime() for more format options
Have a nice day,
Chris

A(Answer):

On Wed, 07 Jan 2004 16:16:35 +0100, dr. zoidberg wrote:

I’m trying do display weekdays with dates, monday to sunday, but only for
current week, something like small calendar.

DZ..

Check out <http://www.phpbuilder.com/> and do a quick search / hunt for a
calendar app / code on there. One does exist.

Pre-warning… the code doesn’t work 100% as it’s entered on the site.. I
tried to use it a while back but broke horrible, however, it does have the
data / "formula" for displaying dates relative to days (including "empty
ones".. ie: it knows the start day of the month and the end day for
example) and might help you on your way to what you’re aiming for =)
HTH.

Regards,

Ian


Ian.H [Design & Development]
digiServ Network – Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.

A(Answer):

Pedro Graca wrote:

dr. zoidberg wrote:

I’m trying do display weekdays with dates, monday to sunday, but only
for current week, something like small calendar.

<?php
$wd_arr = array(‘Mo ‘, ‘Tu ‘, ‘We ‘, ‘Th ‘, ‘Fr ‘, ‘Sa ‘, ‘Su ‘);
$monday = mktime(0, 0, 0, // hour, minute, second
(int)date(‘m’), // month
(int)date(‘d’)+(1-(int)date(‘w’)), // day (can be negative!)
(int)date(‘Y’)); // year

for ($n=0; $n<7; $n++) {
echo $wd_arr[$n], date(‘Y-m-d’, $monday+$n*60*60*24), "<br/>\n";
}
?>

Great script.

Few adjustment and I created what I want. TNX

LEAVE A COMMENT