i want to diaplay which week this is from a selected date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpchild
Forum Newbie
Posts: 20
Joined: Mon Jul 31, 2006 6:27 am

i want to diaplay which week this is from a selected date

Post by phpchild »

hi,

now i am stuggling with date format problem. i want to display a week from the selected date from the database.

for example

if i retrive the date like 6-7-2006 from the database, it should be show like 01-07-2006 to 07-07-2006 from database

thank U
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Is it just any database or a specific one, meaning: can you use "special" functions of your database or should it be generic/php code?
phpchild
Forum Newbie
Posts: 20
Joined: Mon Jul 31, 2006 6:27 am

Post by phpchild »

hi

thanks for ur reply.

i don't know any special functions if u know please tell me
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

e.g. there is WEEK(date[,mode]) and WEEKDAY(date) for mysql, http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
and strtotime for php, http://de2.php.net/strtotime
and date, http://de2.php.net/date

really depends on what you have and what you want to use.
phpchild
Forum Newbie
Posts: 20
Joined: Mon Jul 31, 2006 6:27 am

Post by phpchild »

hi


but i want to display starting date and ending date from the week

like

if i choose 6-07-2006

it should show

starting date 01-07-06

ending date 07-07-06
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

From saturday to friday? That's a strange week. Anyway...

It's an easy task with strtotime in php.

Code: Select all

<?php
$tsEnd = strtotime('2006-07-06 friday');
$tsStart = strtotime('last saturday', $tsEnd);

echo date('d.m.Y', $tsEnd), " \n", date('d.m.Y', $tsStart);
?>
Post Reply