Jump to content


Photo

How do I find weeknumber for given date without using mktime (UNIX timestamp)?


  • Please log in to reply
2 replies to this topic

#1 Tore

Tore
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationNorway

Posted 30 April 2006 - 10:43 AM

Hi.

I would like to be able to find weeknumber and weekdaynumber
without using the UNIX timestamp (e.g use of mktime).

I'm looking for a function that use a date to calculate the above.

The reason I'm asking is that I would like to display calendars further back in time that the UNIX timestamp handles.

Does anyone out there know if there is a custom function somewhere that are able to calculate which weeknumber
a given date is within?

would also appreciate something that also find the
weekdaynumber for a given date, preferably for both using
monday and sunday as the first day of the week?
Tore

#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 01 May 2006 - 06:59 AM

Haven't used this myself but looks like a good place to start
[a href=\"http://au.php.net/calendar\" target=\"_blank\"]Calendar[/a]

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 May 2006 - 10:54 AM

This could be a usable workaround. If you take my birthday Saturday, Jan 22nd, 1949, and given that the calendar repeats itself exactly every 28 years,

<?php
  $dob = '1949-01-22';
  $yr = substr($dob, 0, 4);
  $tmpyr  = $yr + 28;
  $tmpdob = str_replace($yr, $tmpyr, $dob);
  
  echo "Born on a " . date('l', strtotime($tmpdob)) . " in week #" . date('W', strtotime($tmpdob));
?>

So basically changing the year from 1949 to 1977 (inside the the 1970 - 2037 unix range).

edit: BTW, this works with PHP5 on Windows :-
<?php
  $dob = '1949-01-22';
  
  echo "Born on a " . date('l', strtotime($dob)) . " in week #" . date('W', strtotime($dob));
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users