Jump to content

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


Tore

Recommended Posts

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?
Link to comment
Share on other sites

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,

[code]<?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));
?>[/code]

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

edit: BTW, this works with PHP5 on Windows :-
[code]<?php
  $dob = '1949-01-22';
  
  echo "Born on a " . date('l', strtotime($dob)) . " in week #" . date('W', strtotime($dob));
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.