[SOLVED] getting weeknumber from 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
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

[SOLVED] getting weeknumber from date

Post by ryuuka »

o/

the problem is this i want to build a script that takes the time out of the database
and converts it to a different value.
now this would normally not be a problem but i want the weeknumber
(say week 1 to 52)
the problem here is that the only dates i have are like this: 01-08-2006 (the date is from a database)
i need a week number for this what i have is the following:

Code: Select all

$weeknr = date("W", strtotime($s_date));
echo "$weeknr<br>";
      
echo $s_datum;
the resullt for this is:
01
3-8-2006

W stands for the weeknumber
and the strtotime is supposed to disect the date

what am i doing wrong and can i get a pointer in the right direction
Last edited by ryuuka on Thu Nov 02, 2006 6:06 am, edited 2 times in total.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

strtotime is probably returning false because of an invalid date format. strtotime may need MM-DD-YYYY format to work.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Why don't you simply select the weeknumber in the database? (Check the date and time functions of the sql dbms you're using...)
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

the problem of getting the weeknumber out of the database is the fact that it isn't there
i need this script to input that into the database
we have a few weeknumbers in the database but for the most part it's just NULL
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Of what type it the date field in the database? What database system is it?
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

the date/Datum field is a datetime field and the weeknummer field is an interger

the database is a mssql and i use php(as viewable in my sig
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Take a look at the Datepart(,) function of mssql
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

ah thanks the datepart did the trick

week is weeknumber and datum is the date table
this query is only for the 2006-9-3 date

Code: Select all

SELECT     DATEPART(week, datum) AS weeknumber
FROM         @@@_printer_stats
WHERE     (naam = 'PR0151') AND (datum = '2006-9-3')
thanks a lot
Post Reply