hi guys
i have a search screen which passes a chosen year and week number.
how can i constitute a fully formated date from these 2 values to use within a SQL Server
date from week number
Moderator: General Moderators
-
AXEmonster
- Forum Commoner
- Posts: 34
- Joined: Fri Sep 05, 2003 11:27 am
- Location: newcastle UK
Re: date from week number
Code: Select all
<?php
$time = mktime(0, 0, 0, $month, 0, $year);
$sql_date_time = date("Y-m-d H:i:s", $time);
$sql_date = date("Y-m-d", $time);
$sql_time = date("Y-m-d H:i:s", $time);
?>-
AXEmonster
- Forum Commoner
- Posts: 34
- Joined: Fri Sep 05, 2003 11:27 am
- Location: newcastle UK
Re: date from week number
in your example how are you handling the WEEK NUMBER (1-52)?
i cant see the solution here?
i cant see the solution here?
Re: date from week number
Code: Select all
date('W'); //18-
AXEmonster
- Forum Commoner
- Posts: 34
- Joined: Fri Sep 05, 2003 11:27 am
- Location: newcastle UK
Re: date from week number
i have but couldnt find an answer
your example will produce the week number using the date() function. This i know and have already
maybe i wasnt clear. I appologise
i would like to take the following values (variables)
week no = 18
year =2006
now reconstitute a date from those two into (yyyy/mm/dd)
your example will produce the week number using the date() function. This i know and have already
maybe i wasnt clear. I appologise
i would like to take the following values (variables)
week no = 18
year =2006
now reconstitute a date from those two into (yyyy/mm/dd)
Re: date from week number
Ok think about this for a second... How many days are in a week? 7, right? Alright, so, you're going to have a function that determines how many weeks are in the year and a day to run off of for the starting date of the week. Then format it. Whether it be Monday or Sunday or whatever you use. What makes it complicated is you want to input the year also. So let's try this:
I had this code sitting around somewhere. Don't remember where it came from though. lucky you. 
Code: Select all
function dateByWkYr($year, $week) {
$first_day_of_yr = strtotime("1 January ".($year ? $year : date("Y")));
// 10=sunday, 11=monday, 12=tuesday, etc. etc.
// depending on what day of the week you want to start on
// you can also add a $day in the function and search by the array
$first_day = (11 - date('w', $first_day_of_yr)) % 7 - 3;
$day = strtotime(($week - 1) . ' weeks '.$first_day.' days', $first_day_of_yr);
return $day;
}
$year = date('Y');
$week = date('w');
$date = date('F j, Y, g:i a', dateByWkYr($year, $week));
echo 'week '.$week.' of '.$year.' begins on '.$date;
-
AXEmonster
- Forum Commoner
- Posts: 34
- Joined: Fri Sep 05, 2003 11:27 am
- Location: newcastle UK
Re: date from week number
cheers
will test it and let you know
will test it and let you know