?
Solved

How to get weeknumbers from a date-serial number

Posted on 2001-07-12
18
Medium Priority
?
224 Views
Last Modified: 2006-11-17
Hi,

I have a variable with a date serial in it.
For example: Friday, July 13 8:00 AM is in serial 995004000.
What I would like is to get the weeknumber out of this serial number. And Friday, July 13th is weeknumber 28.
Is there someone who can help me solving this problem?

Thanks,
Hinke
0
Comment
Question by:hinkeltje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 4

Expert Comment

by:ykf2000
ID: 6279657
how do you get 995004000 from Friday, July 13 8:00 AM? is that a unix timestamp?
0
 

Author Comment

by:hinkeltje
ID: 6279667
Yes it is.
0
 

Author Comment

by:hinkeltje
ID: 6279678
Yes it is.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:ykf2000
ID: 6279690
try this:

<?
     $your_time = 995004000;
     $day = date("j",$your_time);
     $month = date("n",$your_time);
     $year = date("Y",$your_time);
     $total_days = $day;
     
     for($i=1;$i<=$month;$i++)
     {
          $total_days = $total_days + date("t",mktime (0,0,0,$day,$month,$year));
     }

     $number_of_weeks = $total_days / 7;
?>
0
 

Author Comment

by:hinkeltje
ID: 6279712
It's not giving me the correct answer.
$number_of_weeks has result 32.857142857143
But 995004000 is in week 28.
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6279749
OK sorry some technical mistake. This should work very fine.

<?
     $your_time = 995004000;
     $day = date("j",$your_time);
     $month = date("n",$your_time);
     $total_days = $day;
     
     for($i=1;$i<$month;$i++)
     {
          $total_days = $total_days + date("t",mktime (0,0,0,$i,$day,$year));
     }
     $number_of_weeks = round($total_days / 7);
     echo $number_of_weeks;
?>
0
 

Author Comment

by:hinkeltje
ID: 6279783
Ok, this is giving me the correct result back for Friday 13 July.
But if I give Mon 9th July, it gives me week 27, but Mon 9th July is still week 28.
It seems that your week ends on wednesday and starts on thursday. But (ofcourse) it need to start on mondays and ending on sundays.
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6279804
ok try this again: :)


<?
     $your_time = mktime (0,0,0,7,1,2001);
     $day = date("j",$your_time);
     $month = date("n",$your_time);
     $total_days = $day;
     
     for($i=1;$i<$month;$i++)
     {
          $total_days = $total_days + date("t",mktime (0,0,0,$i,$day,$year));
     }
     $remainder = ($total_days / 7) - round($total_days / 7);
     $number_of_weeks = round($total_days / 7);
     if($remainder > 0 && $remainder < 0.5)
          $number_of_weeks = $number_of_weeks + 1;
     echo $number_of_weeks;
?>
0
 

Author Comment

by:hinkeltje
ID: 6279826
I think we are almost there :-)
But your week starts at sunday, and I want my week to start on monday.

So for example:
week 27  mon July 2nd till sun July 8th
week 28  mon July 9th till sun July 15th
week 29  mon July 16th till sun July 22nd
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6279901
ok gotcha:


<?
     $your_time = mktime (0,0,0,7,22,2001);
     $day = date("j",$your_time);
     $month = date("n",$your_time);
     $total_days = $day;
     
     for($i=1;$i<$month;$i++)
     {
          $total_days = $total_days + date("t",mktime (0,0,0,$i,$day,$year));
     }
     $remainder = ($total_days / 7) - round($total_days / 7);
     $number_of_weeks = round($total_days / 7);
     
     if($remainder > 0.15 && $remainder < 0.65)
          $number_of_weeks = $number_of_weeks + 1;
     echo $number_of_weeks;
?>
0
 

Author Comment

by:hinkeltje
ID: 6279977
Thanks, this seems to work. But.... you use:
mktime (0,0,0,7,15,2001)
And I am using: 995004000
And if I use the integer above, it gives me back week 28 all the time.
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6279982
That number is a constant and sure enough it gives 28 all the time because that number represents 13th July 2001 which is the 28th week.
0
 
LVL 4

Accepted Solution

by:
ykf2000 earned 800 total points
ID: 6279989
if you wanna have different timestamps, let's you want todays time stamp then use

$today_timestamp = mktime(0,0,0,date("n"),date("j"),date("Y"));
0
 

Author Comment

by:hinkeltje
ID: 6279990
Yeah duh... and if I change the number (let's say add an extra 10 days) it still gives me back week 28.
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6279998
what do u mean add another 10 days? You can't just add 10 to that number. It does not work that way.
0
 

Author Comment

by:hinkeltje
ID: 6280010
I can add an extra 10 days to that number :-)

time()+(86400*10)
It is representing today plus an extra 10 days.

And 86400 comes from 86400 seconds in one day: 24 * 60 * 60
0
 

Author Comment

by:hinkeltje
ID: 6280023
Thank you ykf2000 for your help (and time).
It works perfect now.
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6280026
great :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question