Jump to content

Php Calculating the week number for a given date


kamal213

Recommended Posts

That's not going to work without the date in the correct format. (23/10/2011 will result in week 01, should be 42). You require the date as follows: YYYY-MM-DD

 

<?php
$a = '2011-10-23';
$week_num =  date('W', strtotime($a));
echo $week_num;
?>

 

Use the php manual to find answers

 

http://php.net/date

thanks for the correction neil. Schoolboy error on my behalf. kamal213, if you need to convert uk into a week number then one option is:

<?php
list($day,$month,$year) = explode('/','15/11/2011');
$weekNumber = date('W',mktime(0,0,0,$month,$day,$year));
echo $weekNumber;
?>

cheers

gristoi if you were a chick i'd marry you right now! lol

 

You last post is exactly what I was looking for!

 

Thanks aswell neil.johnson especially for correcting gristoi's error but for now I need the uk date format.

 

Thanks guys for your help I taught I would be really complicated but you both made it look simple.

 

Problem Solved!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.