PHP如何从时间戳获取日/小时的时间戳

I want to get a timestamp of the current hour and the current day. How I can do this?

I store a timestamp as a datetime in my database, so I want compare my data like this:

  • How many records were inserted during the current hour
  • How many records were inserted during the current day

Thanks for your help

You can use the mktime function by passing only the details you want and 0 for others (like minutes and seconds)

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )

Given that parameter list you'll have a code like

$timestamp = mktime(date("H"),0,0,date("n"),date("j"),date("Y"));