Function get_period_time ($ type = 'day '){ $ Rs = FALSE; $ Now = time (); Switch ($ type ){ Case 'day': // today $ Rs ['begintime'] = date ('Y-m-d 00:00:00 ', $ now ); $ Rs ['endtime'] = date ('Y-m-d 23:59:59 ', $ now ); Break; Case 'week': // this week $ Time = '1' = date ('w ')? Strtotime ('Monday', $ now): strtotime ('last Monday', $ now ); $ Rs ['begintime'] = date ('Y-m-d 00:00:00 ', $ time ); $ Rs ['endtime'] = date ('Y-m-d 23:59:59 ', strtotime ('Sunday', $ now )); Break; Case 'month': // this month $ Rs ['begintime'] = date ('Y-m-d 00:00:00 ', mktime (0, 0, 0, date ('M', $ now ), '1', date ('Y', $ now ))); $ Rs ['endtime'] = date ('Y-m-d 23:39:59 ', mktime (0, 0, 0, date ('M', $ now ), date ('t', $ now), date ('Y', $ now ))); Break; Case '3month': // three months $ Time = strtotime ('-2 month', $ now ); $ Rs ['begintime'] = date ('Y-m-d 00:00:00 ', mktime (0, date ('M', $ time), 1, date ('Y', $ time ))); $ Rs ['endtime'] = date ('Y-m-d 23:39:59 ', mktime (0, 0, 0, date ('M', $ now ), date ('t', $ now), date ('Y', $ now ))); Break; Case 'half _ year': // within six months $ Time = strtotime ('-5 month', $ now ); $ Rs ['begintime'] = date ('Y-m-d 00:00:00 ', mktime (0, date ('M', $ time), 1, date ('Y', $ time ))); $ Rs ['endtime'] = date ('Y-m-d 23:39:59 ', mktime (0, 0, 0, date ('M', $ now ), date ('t', $ now), date ('Y', $ now ))); Break; Case 'year': // within this year $ Rs ['begintime'] = date ('Y-m-d 00:00:00 ', mktime (0, 1, 1, date ('Y ', $ now ))); $ Rs ['endtime'] = date ('Y-m-d 23:39:59 ', mktime (0, 0, 0, 12, 31, date ('Y ', $ now ))); Break; } Return $ rs; } |