|
|
|
ไม่ทราบว่ามีวิธีอย่างไร ว่าะหว่างวันที่ในปัจจุบัน เช่น ป้อนข้อมูลวันที่ 28-07-2009 โดยในระหว่างอาทิ |
|
|
|
|
|
|
|
<input name=day type=Text size="20" maxlength=40 value="<?
$dateday = date("d");
$datemonth = date("m");
$dateyear = date("y");
$at = array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
if(substr($datemonth,0,1) == "0") {
$ss = substr($datemonth,1,1);
$isa = $ss-1;
} else {
$isa = $datemonth-1;
}
$dmon = $at[$isa];
$datey = "20".$dateyear;
$dayear = $datey;
if($dateday == "10" || $datedayx == "20" || $dateday == "30" )
{
$datedayx = $dateday;
} else {
$datedayx = eregi_replace("0","",$dateday);
}
$day = "".$datedayx." ".$dmon." ".$dayear."";
echo "$day";
?>"/>
|
|
|
|
|
Date :
2009-07-28 15:37:29 |
By :
MOMO |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คนข้างบน ยังไงคะ ไม่เข้าใจ เห็นมันออกมาวันที่เดียว
|
|
|
|
|
Date :
2009-07-29 10:44:19 |
By :
ริทาน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมทำงานอยู่
กำลังทำเรื่องตาราง maintenance พอดี
คิดโค้ดมาเมือกี่มาหมาดๆ 555+
Code (PHP)
<?php
//วันเริ่มต้นตรวจสอบ
$dateStart = '28-07-2009';
//วันสิ้นสุด
$dateEnd = '31-12-2009';
//------------------ เริ่มการทำงาน ห้ามแก้ไขโค้ดใดๆ --------------------//
$allDay = array();
list( $d, $m, $y) = explode('-', $dateStart);
$dateStart = $y . '-' . $m . '-' . $d;
list( $d, $m, $y) = explode('-', $dateEnd);
$dateEnd = $y . '-' . $m . '-' . $d;
$y_start = substr($dateStart,0,4);
$y_end = substr($dateEnd,0,4);
$m_start = substr($dateStart,5,2);
$m_end = substr($dateEnd,5,2);
$d_start = substr($dateStart,8,2);
$d_end = substr($dateEnd,8,2);
$day_start = mktime(0,0,0, $m_start, $d_start, $y_start);
$day_end = mktime(0,0,0, $m_end, $d_end, $y_end);
for ( $y = $y_start; $y <= $y_end; $y++ )
{
for ( $m = 1; $m <= 12; $m++ )
{
$totalday = date('t',mktime(0,0,0, $m, 1, $y) );
for ( $i = 1; $i <= $totalday; $i++ )
{
$current = mktime(0,0,0, $m, $i, $y);
if ( $current >= $day_start && $current <= $day_end )
{
if ( date('w', $current) == 0 || date('w', $current) == 6 )
$allDay[] = $i . '-' . $m . '-' . $y;
}
}
}
}
//------------------ สิ้นสุดการทำงาน --------------------//
echo '<pre>';
print_r( $allDay );
echo '</pre>';
/**
Result
Array
(
[0] => 1-8-2009
[1] => 2-8-2009
[2] => 8-8-2009
[3] => 9-8-2009
[4] => 15-8-2009
[5] => 16-8-2009
[6] => 22-8-2009
[7] => 23-8-2009
[8] => 29-8-2009
[9] => 30-8-2009
[10] => 5-9-2009
[11] => 6-9-2009
[12] => 12-9-2009
[13] => 13-9-2009
[14] => 19-9-2009
[15] => 20-9-2009
[16] => 26-9-2009
[17] => 27-9-2009
[18] => 3-10-2009
[19] => 4-10-2009
[20] => 10-10-2009
[21] => 11-10-2009
[22] => 17-10-2009
[23] => 18-10-2009
[24] => 24-10-2009
[25] => 25-10-2009
[26] => 31-10-2009
[27] => 1-11-2009
[28] => 7-11-2009
[29] => 8-11-2009
[30] => 14-11-2009
[31] => 15-11-2009
[32] => 21-11-2009
[33] => 22-11-2009
[34] => 28-11-2009
[35] => 29-11-2009
[36] => 5-12-2009
[37] => 6-12-2009
[38] => 12-12-2009
[39] => 13-12-2009
[40] => 19-12-2009
[41] => 20-12-2009
[42] => 26-12-2009
[43] => 27-12-2009
)
*/
?>
|
|
|
|
|
Date :
2009-07-29 11:58:55 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค้ดอันบน แสดงเฉพาะวันเสาร์กับอาทิตยืเท่านั้นอะ 555+
ส่วนอันนี้ แสดงหมดตั้งแต่วันเริ่มต้น ถึงวันสิ้นสุด
Code (PHP)
<?php
//วันเริ่มต้นตรวจสอบ
$dateStart = '28-07-2009';
//วันสิ้นสุด
$dateEnd = '30-09-2009';
//------------------ เริ่มการทำงาน ห้ามแก้ไขโค้ดใดๆ --------------------//
$allDay = array();
list( $d, $m, $y) = explode('-', $dateStart);
$dateStart = $y . '-' . $m . '-' . $d;
list( $d, $m, $y) = explode('-', $dateEnd);
$dateEnd = $y . '-' . $m . '-' . $d;
$y_start = substr($dateStart,0,4);
$y_end = substr($dateEnd,0,4);
$m_start = substr($dateStart,5,2);
$m_end = substr($dateEnd,5,2);
$d_start = substr($dateStart,8,2);
$d_end = substr($dateEnd,8,2);
$day_start = mktime(0,0,0, $m_start, $d_start, $y_start);
$day_end = mktime(0,0,0, $m_end, $d_end, $y_end);
for ( $y = $y_start; $y <= $y_end; $y++ )
{
for ( $m = 1; $m <= 12; $m++ )
{
$totalday = date('t',mktime(0,0,0, $m, 1, $y) );
for ( $i = 1; $i <= $totalday; $i++ )
{
$current = mktime(0,0,0, $m, $i, $y);
if ( $current >= $day_start && $current <= $day_end )
{
$allDay[] = $i . '-' . $m . '-' . $y;
}
}
}
}
//------------------ สิ้นสุดการทำงาน --------------------//
echo '<pre>';
print_r( $allDay );
echo '</pre>';
/**
Result
Array
(
[0] => 28-7-2009
[1] => 29-7-2009
[2] => 30-7-2009
[3] => 31-7-2009
[4] => 1-8-2009
[5] => 2-8-2009
[6] => 3-8-2009
[7] => 4-8-2009
[8] => 5-8-2009
[9] => 6-8-2009
[10] => 7-8-2009
[11] => 8-8-2009
[12] => 9-8-2009
[13] => 10-8-2009
[14] => 11-8-2009
[15] => 12-8-2009
[16] => 13-8-2009
[17] => 14-8-2009
[18] => 15-8-2009
[19] => 16-8-2009
[20] => 17-8-2009
[21] => 18-8-2009
[22] => 19-8-2009
[23] => 20-8-2009
[24] => 21-8-2009
[25] => 22-8-2009
[26] => 23-8-2009
[27] => 24-8-2009
[28] => 25-8-2009
[29] => 26-8-2009
[30] => 27-8-2009
[31] => 28-8-2009
[32] => 29-8-2009
[33] => 30-8-2009
[34] => 31-8-2009
[35] => 1-9-2009
[36] => 2-9-2009
[37] => 3-9-2009
[38] => 4-9-2009
[39] => 5-9-2009
[40] => 6-9-2009
[41] => 7-9-2009
[42] => 8-9-2009
[43] => 9-9-2009
[44] => 10-9-2009
[45] => 11-9-2009
[46] => 12-9-2009
[47] => 13-9-2009
[48] => 14-9-2009
[49] => 15-9-2009
[50] => 16-9-2009
[51] => 17-9-2009
[52] => 18-9-2009
[53] => 19-9-2009
[54] => 20-9-2009
[55] => 21-9-2009
[56] => 22-9-2009
[57] => 23-9-2009
[58] => 24-9-2009
[59] => 25-9-2009
[60] => 26-9-2009
[61] => 27-9-2009
[62] => 28-9-2009
[63] => 29-9-2009
[64] => 30-9-2009
)
*/
?>
|
|
|
|
|
Date :
2009-07-29 12:03:26 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ่านโจทย์แล้ว สงสัยเรามึนเอง
เดวมาเขียนโค้ดใหม่ หิวข้าวละ 555+
|
|
|
|
|
Date :
2009-07-29 12:06:46 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมให้วันแรกของอาทิตย์นี้ละกันนะ
echo date("Y-m-d",mktime(0, 0, 0, date('m'), date('d') - date('w'), date('Y')));
|
|
|
|
|
Date :
2009-07-29 12:43:07 |
By :
plakrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไปดัดแปลงต่อโดยหา w ของวันที่ input มา ถ้ายังไม่ได้ เดี๋ยวมาเขียนให้ดู
|
|
|
|
|
Date :
2009-07-29 12:44:52 |
By :
plakrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ้าว ผมก็รอพี่อั๋นมาตอบ
งั้น แจกเลยละกัน
แต่โค้ดมันยาวๆ งัยไม่รุ้ อายฟร่ะ เอิ้กๆๆๆๆ 55555555+
Code (PHP)
<?php
//วันเริ่มต้นตรวจสอบ
$dateCheck = '28-07-2009';
//------------------ เริ่มการทำงาน ห้ามแก้ไขโค้ดใดๆ --------------------//
$allDay = array();
list( $d, $m, $y) = explode('-', $dateCheck);
$dateCheck = $y . '-' . $m . '-' . $d;
$y_Check = substr($dateCheck,0,4);
$m_Check = ( substr($dateCheck,5,2) * 1 );
$d_Check = ( substr($dateCheck,8,2) * 1 );
$day_Check = mktime(0,0,0, $m_Check, $d_Check, $y_Check);
$totalDay = date('t', mktime(0,0,0, $m_Check, $d_Check, $y_Check));
$w_check = date('w', mktime(0,0,0, $m_Check, $d_Check, $y_Check));
if ( $w_check != 0 )
$start_day = date('j', mktime(0,0,0, $m_Check, $d_Check - $w_check, $y_Check));
else
$start_day = $d_Check;
if ( $w_check != 6 )
$end_day = date('j', mktime(0,0,0, $m_Check, $d_Check + ( 6 - $w_check), $y_Check));
else
$end_day = $d_Check;
if ( $start_day > $d_Check )
{
$count = 0;
for ( $i = $start_day; $i <= date('t', mktime(0,0,0, ( $m_Check - 1), $d_Check, $y_Check)); $i++ )
{
$days = $i . '-' . ( $m_Check - 1 ) . '-' . $y_Check;
$allDay[] = $days;
$count++;
}
for ( $i = 1; $i <= ( 7 - $count ); $i++ )
{
$days = $i . '-' . $m_Check . '-' . $y_Check;
if ( date('w', mktime(0, 0, 0, $m_Check, $i, $y_Check) ) <= 6 )
{
$allDay[] = $days;
}
}
}
else
{
$count = 0;
for ( $i = $start_day; $i <= date('t', mktime(0,0,0, $m_Check, $d_Check, $y_Check)); $i++ )
{
$days = $i . '-' . $m_Check . '-' . $y_Check;
if ( $count < 7 )
{
$allDay[] = $days;
$count++;
}
}
if ( $count < 7 )
{
for ( $i = 1; $i <= ( 7 - $count); $i++ )
{
$days = $i . '-' . ( $m_Check + 1 ) . '-' . $y_Check;
$allDay[] = $days;
}
}
}
//------------------ สิ้นสุดการทำงาน --------------------//
echo 'วันที่ ' . $dateCheck . '<br />';
echo '<pre>';
print_r( $allDay );
echo '</pre>';
/**
Result
วันที่ 2009-07-28
Array
(
[0] => 26-7-2009
[1] => 27-7-2009
[2] => 28-7-2009
[3] => 29-7-2009
[4] => 30-7-2009
[5] => 31-7-2009
[6] => 1-8-2009
)
*/
?>
|
|
|
|
|
Date :
2009-07-29 14:25:33 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จัดไปตามคำขอของดุนยา
Code (PHP)
<?php
$input = "2009-07-30";
$time = strtotime('last sunday', strtotime($input));
for($i=0;$i<7;$i++){
echo "<br>" . date("Y-m-d", strtotime(date("Y-m-d", $time) . " +" . $i . " day"));
}
?>
|
|
|
|
|
Date :
2009-08-01 00:30:04 |
By :
plakrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ๊ากก พี่อั๋น ทำไปได้
โค้ดสั้นจิดเดียว เอิ้กๆ
ผมยังไม่เคยได้ใช้ strtotime อะ เอิ้กๆๆๆๆๆๆ
|
|
|
|
|
Date :
2009-08-01 00:59:42 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค๊ดสั้นอะ แต่อย่างอื่นไม่สั้น
|
|
|
|
|
Date :
2009-08-01 01:36:08 |
By :
plakrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ่า ติดเรทกานอีกละ แบน แบน แบน 555+
|
|
|
|
|
Date :
2009-08-01 08:31:44 |
By :
gummezaka |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5555+
|
|
|
|
|
Date :
2009-08-01 10:43:27 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมหมายถึง สายตายาวอะครับ คิดมากไปไหม อิอิ
|
|
|
|
|
Date :
2009-08-01 14:54:07 |
By :
plakrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|