本文實例講述了php根據(jù)年月獲取當月天數(shù)及日期數(shù)組的方法。分享給大家供大家參考,具體如下:
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供廣靈網(wǎng)站建設(shè)、廣靈做網(wǎng)站、廣靈網(wǎng)站設(shè)計、廣靈網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、廣靈企業(yè)網(wǎng)站模板建站服務(wù),十余年廣靈做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
function
get_day(
$date
)
{
$tem
=
explode('-'
,
$date);
//切割日期
得到年份和月份
$year
=
$tem['0'];
$month
=
$tem['1'];
if(
in_array($month
,
array(
1
,
3
,
5
,
7
,
8
,
01
,
03
,
05
,
07
,
08
,
10
,
12)))
{
//
$text
=
$year.'年的'.$month.'月有31天';
$text
=
'31';
}
elseif(
$month
==
2
)
{
if
(
$year%400
==
||
($year%4
==
$year%100
!==
0)
)
//判斷是否是閏年
{
//
$text
=
$year.'年的'.$month.'月有29天';
$text
=
'29';
}
else{
//
$text
=
$year.'年的'.$month.'月有28天';
$text
=
'28';
}
}
else{
//
$text
=
$year.'年的'.$month.'月有30天';
$text
=
'30';
}
return
$text;
}
echo
get_day('2016-8-1');
運行結(jié)果為:31
改造,返回日期數(shù)組:
/**
*
獲取當月天數(shù)
*
@param
$date
*
@param
$rtype
1天數(shù)
2具體日期數(shù)組
*
@return
*/
function
get_day(
$date
,$rtype
=
'1')
{
$tem
=
explode('-'
,
$date);
//切割日期
得到年份和月份
$year
=
$tem['0'];
$month
=
$tem['1'];
if(
in_array($month
,
array(
1
,
3
,
5
,
7
,
8
,
01
,
03
,
05
,
07
,
08
,
10
,
12)))
{
//
$text
=
$year.'年的'.$month.'月有31天';
$text
=
'31';
}
elseif(
$month
==
2
)
{
if
(
$year%400
==
||
($year%4
==
$year%100
!==
0)
)
//判斷是否是閏年
{
//
$text
=
$year.'年的'.$month.'月有29天';
$text
=
'29';
}
else{
//
$text
=
$year.'年的'.$month.'月有28天';
$text
=
'28';
}
}
else{
//
$text
=
$year.'年的'.$month.'月有30天';
$text
=
'30';
}
if
($rtype
==
'2')
{
for
($i
=
1;
$i
=
$text
;
$i
++
)
{
$r[]
=
$year."-".$month."-".$i;
}
}
else
{
$r
=
$text;
}
return
$r;
}
var_dump(get_day('2016-8-1','2'));
運行結(jié)果如下:
array(31)
{
[0]=
string(8)
"2016-8-1"
[1]=
string(8)
"2016-8-2"
[2]=
string(8)
"2016-8-3"
[3]=
string(8)
"2016-8-4"
[4]=
string(8)
"2016-8-5"
[5]=
string(8)
"2016-8-6"
[6]=
string(8)
"2016-8-7"
[7]=
string(8)
"2016-8-8"
[8]=
string(8)
"2016-8-9"
[9]=
string(9)
"2016-8-10"
[10]=
string(9)
"2016-8-11"
[11]=
string(9)
"2016-8-12"
[12]=
string(9)
"2016-8-13"
[13]=
string(9)
"2016-8-14"
[14]=
string(9)
"2016-8-15"
[15]=
string(9)
"2016-8-16"
[16]=
string(9)
"2016-8-17"
[17]=
string(9)
"2016-8-18"
[18]=
string(9)
"2016-8-19"
[19]=
string(9)
"2016-8-20"
[20]=
string(9)
"2016-8-21"
[21]=
string(9)
"2016-8-22"
[22]=
string(9)
"2016-8-23"
[23]=
string(9)
"2016-8-24"
[24]=
string(9)
"2016-8-25"
[25]=
string(9)
"2016-8-26"
[26]=
string(9)
"2016-8-27"
[27]=
string(9)
"2016-8-28"
[28]=
string(9)
"2016-8-29"
[29]=
string(9)
"2016-8-30"
[30]=
string(9)
"2016-8-31"
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php日期與時間用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
不知道你對php操作文件的方法熟不熟悉,用fgets()方法逐行讀取txt文件中的數(shù)據(jù),每讀取一行對這一行的其實幾個字符進行正則匹配或者直接全字符比對看是否對應(yīng)當前日期,對應(yīng)就得到你需要的當前行數(shù)據(jù),不對應(yīng)就繼續(xù)讀取下一行直到得到為止。然后得到的是這一行的字符串數(shù)據(jù),你可以用分割字符串的方法把字符串分割成數(shù)組然后想要怎么處理都可以的。
$rows?=?mysql_num_rows(mysql_query("select?*?from?biao?where?gtime?=".$start));?
echo?$rows;
把日期寫入數(shù)據(jù)庫 查詢 select * from XXX order by uptime limit 10;
uptime 就是日期
文章標題:php按照日期提取數(shù)據(jù) php按照日期提取數(shù)據(jù)的方法
本文鏈接:http://muchs.cn/article2/hjcioc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計、網(wǎng)站內(nèi)鏈、App開發(fā)、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)