|
|
|
สงสัย week ที่ 35 มีฟังชั่นอะไรบ้างที่สามารถแปลงค่า week ให้เป็นวันระหว่างได้บ้างค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$year = 2000;
$week =35;
$start = date("l, M jS, Y", strtotime("01 Jan ".$year." 00:00:00 GMT + ".$week." weeks"));
$end = date("l, M jS, Y", strtotime($start." + 1 week"));
echo $start." to ".$end;
?>
|
|
|
|
|
Date :
2013-09-03 13:41:42 |
By :
ctr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไมมันแปลงไม่ตรงกับ 1 - 7/9/2013 (อาทิตย์-เสาร์) เลยค่ะ
Saturday, Sep 2nd, 2000 to Saturday, Sep 9th, 2000
Code (PHP)
<?php
$year = 2000;
$week =35;
$start = date("l, M jS, Y", strtotime("01 Jan ".$year." 00:00:00 GMT + ".$week." weeks"));
$end = date("l, M jS, Y", strtotime($start." + 1 week"));
echo $start." to ".$end;
?>
ลองเปลี่ยนเป็น 2013
Tuesday, Sep 3rd, 2013 to Tuesday, Sep 10th, 2013
Code (PHP)
<?php
$year = 2013;
$week =35;
$start = date("l, M jS, Y", strtotime("01 Jan ".$year." 00:00:00 GMT + ".$week." weeks"));
$end = date("l, M jS, Y", strtotime($start." + 1 week"));
echo $start." to ".$end;
?>
|
ประวัติการแก้ไข 2013-09-03 14:29:33 2013-09-03 14:52:48
|
|
|
|
Date :
2013-09-03 14:29:10 |
By :
loomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?php
$tempDate = '2010-09-01';
echo date('W', strtotime( $tempDate));?>
ลองปรับเอาไปใช้ดู
|
|
|
|
|
Date :
2013-09-03 14:53:32 |
By :
ctr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
$year = 2013;
$week_no=35;
$week_start = new DateTime();
$week_start->setISODate($year,$week_no);
echo $week_start->format('d-M-Y'); ?>
|
|
|
|
|
Date :
2013-09-03 15:05:40 |
By :
ctr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ คุณ ctr
Code (PHP)
<?php
$year = 2013;
$week_no=35;
$week_start = new DateTime();
$week_start->setISODate($year,$week_no);
echo $week_start->format('d-M-Y'); ?>
ได้ผลลัพธ์ คือ 26-Aug-2013
มันก็ไม่ตรงกับ week ที่ 35 ของวันที่ระหว่าง 1 - 7/9/2013 (อาทิตย์-เสาร์) ค่ะ
|
|
|
|
|
Date :
2013-09-03 15:19:47 |
By :
loomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
$ddate = "2013-9-01";
$duedt = explode("-", $ddate);
$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);
$week = (int)date('W', $date);
echo "Weeknummer: " . $week;
?>
ลองปรับดูน่าจะใช้ได้
|
|
|
|
|
Date :
2013-09-03 15:40:18 |
By :
ctr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าได้ผลลัพธ์ไม่ตรงกับน้อง loomoo น้องloomoo แน่ใจแล้วเหรอค่ะว่าน้องนับได้ถูกต้องจริงๆ
<?php
$weekNo = 35;
$year = 2013;
for($day=1; $day<=7; $day++)
{
echo date('d/m/Y', strtotime($year."W".$weekNo.$day)),"<br />";
}
?>
|
|
|
|
|
Date :
2013-09-03 16:32:11 |
By :
survivor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หนู อยากนับเป็น (อาทิตย์-เสาร์) แบบนี้ค่ะ
เช่น
1 - 7 ก.ย 2556
8 - 14 ก.ย 2556
15 - 21 ก.ย 2556
22 - 28 ก.ย 2556
29 - 30 ก.ย 2556
พอจะเป็นไปได้ไหมค่ะ คุณ LittleLovely
|
|
|
|
|
Date :
2013-09-03 16:42:58 |
By :
loomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
$year=2013;
for($m=1; $m<=12; ++$m )
$lastdayOfMonth[$m] = date('t', strtotime("$year-$m-01"));
foreach($lastdayOfMonth as $month => $lastday){
for($d=1; $d<=$lastday; ++$d){
echo "$d/$month/$year,";
if($d%7==0)
echo "<br />";
}echo "<br />";
}
?>
ผลลัพธ์ที่ได้ค่ะ
Quote:1/1/2013,2/1/2013,3/1/2013,4/1/2013,5/1/2013,6/1/2013,7/1/2013,
8/1/2013,9/1/2013,10/1/2013,11/1/2013,12/1/2013,13/1/2013,14/1/2013,
15/1/2013,16/1/2013,17/1/2013,18/1/2013,19/1/2013,20/1/2013,21/1/2013,
22/1/2013,23/1/2013,24/1/2013,25/1/2013,26/1/2013,27/1/2013,28/1/2013,
29/1/2013,30/1/2013,31/1/2013,
1/2/2013,2/2/2013,3/2/2013,4/2/2013,5/2/2013,6/2/2013,7/2/2013,
8/2/2013,9/2/2013,10/2/2013,11/2/2013,12/2/2013,13/2/2013,14/2/2013,
15/2/2013,16/2/2013,17/2/2013,18/2/2013,19/2/2013,20/2/2013,21/2/2013,
22/2/2013,23/2/2013,24/2/2013,25/2/2013,26/2/2013,27/2/2013,28/2/2013,
1/3/2013,2/3/2013,3/3/2013,4/3/2013,5/3/2013,6/3/2013,7/3/2013,
8/3/2013,9/3/2013,10/3/2013,11/3/2013,12/3/2013,13/3/2013,14/3/2013,
15/3/2013,16/3/2013,17/3/2013,18/3/2013,19/3/2013,20/3/2013,21/3/2013,
22/3/2013,23/3/2013,24/3/2013,25/3/2013,26/3/2013,27/3/2013,28/3/2013,
29/3/2013,30/3/2013,31/3/2013,
1/4/2013,2/4/2013,3/4/2013,4/4/2013,5/4/2013,6/4/2013,7/4/2013,
8/4/2013,9/4/2013,10/4/2013,11/4/2013,12/4/2013,13/4/2013,14/4/2013,
15/4/2013,16/4/2013,17/4/2013,18/4/2013,19/4/2013,20/4/2013,21/4/2013,
22/4/2013,23/4/2013,24/4/2013,25/4/2013,26/4/2013,27/4/2013,28/4/2013,
29/4/2013,30/4/2013,
1/5/2013,2/5/2013,3/5/2013,4/5/2013,5/5/2013,6/5/2013,7/5/2013,
8/5/2013,9/5/2013,10/5/2013,11/5/2013,12/5/2013,13/5/2013,14/5/2013,
15/5/2013,16/5/2013,17/5/2013,18/5/2013,19/5/2013,20/5/2013,21/5/2013,
22/5/2013,23/5/2013,24/5/2013,25/5/2013,26/5/2013,27/5/2013,28/5/2013,
29/5/2013,30/5/2013,31/5/2013,
1/6/2013,2/6/2013,3/6/2013,4/6/2013,5/6/2013,6/6/2013,7/6/2013,
8/6/2013,9/6/2013,10/6/2013,11/6/2013,12/6/2013,13/6/2013,14/6/2013,
15/6/2013,16/6/2013,17/6/2013,18/6/2013,19/6/2013,20/6/2013,21/6/2013,
22/6/2013,23/6/2013,24/6/2013,25/6/2013,26/6/2013,27/6/2013,28/6/2013,
29/6/2013,30/6/2013,
1/7/2013,2/7/2013,3/7/2013,4/7/2013,5/7/2013,6/7/2013,7/7/2013,
8/7/2013,9/7/2013,10/7/2013,11/7/2013,12/7/2013,13/7/2013,14/7/2013,
15/7/2013,16/7/2013,17/7/2013,18/7/2013,19/7/2013,20/7/2013,21/7/2013,
22/7/2013,23/7/2013,24/7/2013,25/7/2013,26/7/2013,27/7/2013,28/7/2013,
29/7/2013,30/7/2013,31/7/2013,
1/8/2013,2/8/2013,3/8/2013,4/8/2013,5/8/2013,6/8/2013,7/8/2013,
8/8/2013,9/8/2013,10/8/2013,11/8/2013,12/8/2013,13/8/2013,14/8/2013,
15/8/2013,16/8/2013,17/8/2013,18/8/2013,19/8/2013,20/8/2013,21/8/2013,
22/8/2013,23/8/2013,24/8/2013,25/8/2013,26/8/2013,27/8/2013,28/8/2013,
29/8/2013,30/8/2013,31/8/2013,
1/9/2013,2/9/2013,3/9/2013,4/9/2013,5/9/2013,6/9/2013,7/9/2013,
8/9/2013,9/9/2013,10/9/2013,11/9/2013,12/9/2013,13/9/2013,14/9/2013,
15/9/2013,16/9/2013,17/9/2013,18/9/2013,19/9/2013,20/9/2013,21/9/2013,
22/9/2013,23/9/2013,24/9/2013,25/9/2013,26/9/2013,27/9/2013,28/9/2013,
29/9/2013,30/9/2013,
1/10/2013,2/10/2013,3/10/2013,4/10/2013,5/10/2013,6/10/2013,7/10/2013,
8/10/2013,9/10/2013,10/10/2013,11/10/2013,12/10/2013,13/10/2013,14/10/2013,
15/10/2013,16/10/2013,17/10/2013,18/10/2013,19/10/2013,20/10/2013,21/10/2013,
22/10/2013,23/10/2013,24/10/2013,25/10/2013,26/10/2013,27/10/2013,28/10/2013,
29/10/2013,30/10/2013,31/10/2013,
1/11/2013,2/11/2013,3/11/2013,4/11/2013,5/11/2013,6/11/2013,7/11/2013,
8/11/2013,9/11/2013,10/11/2013,11/11/2013,12/11/2013,13/11/2013,14/11/2013,
15/11/2013,16/11/2013,17/11/2013,18/11/2013,19/11/2013,20/11/2013,21/11/2013,
22/11/2013,23/11/2013,24/11/2013,25/11/2013,26/11/2013,27/11/2013,28/11/2013,
29/11/2013,30/11/2013,
1/12/2013,2/12/2013,3/12/2013,4/12/2013,5/12/2013,6/12/2013,7/12/2013,
8/12/2013,9/12/2013,10/12/2013,11/12/2013,12/12/2013,13/12/2013,14/12/2013,
15/12/2013,16/12/2013,17/12/2013,18/12/2013,19/12/2013,20/12/2013,21/12/2013,
22/12/2013,23/12/2013,24/12/2013,25/12/2013,26/12/2013,27/12/2013,28/12/2013,
29/12/2013,30/12/2013,31/12/2013,
|
|
|
|
|
Date :
2013-09-03 17:12:46 |
By :
survivor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จากโค๊ดนี้มันเยี่ยมมากเลยค่ะ
Code (PHP)
$year=2013;
for($m=1; $m<=12; ++$m )
$lastdayOfMonth[$m] = date('t', strtotime("$year-$m-01"));
foreach($lastdayOfMonth as $month => $lastday){
for($d=1; $d<=$lastday; ++$d){
if($d%7==1)
echo "$d/$month/$year-";
if($d==$lastday)
echo "$d/$month/$year";
elseif($d%7==0)
echo "$d/$month/$year<br />\n";
}echo "<br /><br />\n";
}
แต่ถ้าหนูส่งค่าสัปดาห์มาเป็น week เพียงสัปดาห์ เช่น
ส่ง GET คือ week=42 แล้วให้แปลงเป็น 8/9/2013-14/9/2013 ได้ไหมค่ะ
ขอบคุณมากๆ ที่ช่วยเหลือจุง ^.^
|
|
|
|
|
Date :
2013-09-04 09:26:14 |
By :
loomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ ขอบคุณทุกความช่วยเหลือนะค่ะ
|
|
|
|
|
Date :
2013-09-04 11:46:07 |
By :
loomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|