469,323 Members | 1,553 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Get date based on weekday?

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

Jul 17 '05 #1
6 11065
"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.
Jul 17 '05 #2
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.

Jul 17 '05 #3
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 =--
Jul 17 '05 #4
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
Jul 17 '05 #5
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.

Jul 17 '05 #6
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
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Alicia | last post: by
1 post views Thread by Liz Malcolm | last post: by
3 posts views Thread by Bob Sanderson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.