Home Backend Development PHP Tutorial php如何判断当前时间在某个时间范围内

php如何判断当前时间在某个时间范围内

Mar 30, 2017 am 10:43 AM

 php怎么判断当前时间在某个时间范围内?
我有一个节目表功能,输出当天的节目单安排。。
主要有 节目名称 节目介绍 和 节目开始时间和节目结束时间。。
我要怎么判断当前时间输出的是哪一个?

lz最好能把表详细列出来

  • SQL code

SELECT * FROM `table` WHERE CURRENT_TIME() BETWEEN `开始时间` AND `结束时间`;
Copy after login

数据库是不是可以存一个区域呢。一个开始一个结束。这样不就好办了?

如果你节目单是周期性的,那就有多个判断拉。

swtch($weeks){
 case 1:
3:00 - 5:00->a节目表,5:00 - 6:00->b节目表,6:00-9:00->节目表c}这样的(做相应的判断就可)
 case 2:
 {3:00 - 5:00->a节目表,5:00 - 5:30->B节目表,5:30 - 6:00->D节目表,8:00-9:30->C节目表}(同理)
}
Copy after login

为啥搞这么纠结...

节目表是有规律的是吧? 那么只要在数据库中记录每个节目的起始时间,用unixtimestamp表示,只要

节目开始 < 当前时间 < 节目结束 不就行了么?

然后就是定时去填充节目表就行呗..

你早给出表结构,问题早就解决了!

现在的日期 now()

今天周几 weekday(now())

今天有哪些节目播出 find_in_set(weekday(now()), `week`) 注意你的 week 字段名是 mysql 保留字

现在的时间 curtime()

当前的时间在哪个时间段 curtime() between start_time and finish_time

组合在一起

select * from tbl_name where find_in_set(weekday(now()),`week`) 
and curtime() between start_time and finish_time
Copy after login

以上就是 php如何判断当前时间在某个时间范围内 的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Get the current time using DateTime.Now function in C# Get the current time using DateTime.Now function in C# Nov 18, 2023 pm 03:14 PM

Use the DateTime.Now function in C# to get the current time. In C# programming, we often need to get the current time. The DateTime.Now function is provided in C# to obtain the current system time. Below I will introduce to you how to use the DateTime.Now function and give specific code examples. The DateTime.Now function returns a DateTime object representing the current date and time. Its usage is very simple, just call the function. Below is one

How to get the current date and time using MySQL's NOW function How to get the current date and time using MySQL's NOW function Jul 25, 2023 am 09:29 AM

How to use MySQL's NOW function to get the current date and time. MySQL is a popular relational database management system that is widely used in various applications. In many cases, we need to get the current date and time to perform database operations. MySQL's NOW function is a very useful function that can help us get the current date and time easily. The NOW function is a built-in function provided by MySQL for obtaining the current date and time. Its syntax is very simple, you only need to use it in the query statement

How to get the current time using the TIME function in MySQL How to get the current time using the TIME function in MySQL Jul 13, 2023 am 09:31 AM

How to use the TIME function in MySQL to obtain the current time. When developing applications, it is often necessary to obtain the current time or only care about the time part. The TIME function in MySQL can help us easily obtain the current time. It can return a value representing the current time. This article will introduce how to use the TIME function in MySQL and some common usages. First, let us understand the syntax of the TIME function: TIME() The TIME function does not require any parameters and can be used directly. it will

Use the time.Since function to calculate the time interval between the specified time and the current time Use the time.Since function to calculate the time interval between the specified time and the current time Jul 24, 2023 am 08:57 AM

Using the time.Since function to calculate the time interval between a specified time and the current time is a valuable resource for each of us. In programming, we often need to calculate time intervals to perform some scheduled tasks or determine the execution time of certain operations. In Go language, we can use the Since function in the time package to calculate the time interval between the specified time and the current time. The time.Since function is defined as follows: funcSince(ttime.Time)time

Get the current time using the time.Now function in the Go language documentation Get the current time using the time.Now function in the Go language documentation Nov 04, 2023 pm 04:06 PM

Title: Example of getting the current time using Go language Text: Go language is a programming language known for its simplicity and efficiency. It provides a rich standard library to make daily coding tasks easy and enjoyable. Among them, the time package is a very useful standard library provided by the Go language, which can help us handle and operate time-related tasks. In this article, we will learn how to get the current time using Go’s time.Now function. The following is the specific code implementation: packagemain

Use the time.Now function to get the current time Use the time.Now function to get the current time Jul 24, 2023 pm 02:37 PM

Use the time.Now function to get the current time In the Go programming language, we can use the Now function in the time package to get the current time. The time.Now function returns a time.Time type value that contains the current date and time information. Here is a sample code that demonstrates how to use the time.Now function to get the current time and output the result: packagemainimport("fmt"

MySQL time range comparison: examples and analysis MySQL time range comparison: examples and analysis Mar 01, 2024 pm 04:12 PM

MySQL is a commonly used relational database management system used to store and manage data. In practical applications, comparison and filtering of time ranges are often involved. This article will introduce in detail how to compare time ranges in MySQL from two aspects: examples and analysis, and provide specific code examples. The example assumes that there is a table named orders, which stores order information, including order number, order time and other fields. Now we need to query the order data within the past week. Here is an example: SE

Learn the application of MySQL time range relationship from scratch Learn the application of MySQL time range relationship from scratch Mar 01, 2024 pm 03:39 PM

MySQL is a popular relational database management system widely used in various websites and applications. To learn the application of MySQL time range relationships, we first need to understand the concept of time range relationships and how to use related syntax for query operations in MySQL. The concept of time range relationship In MySQL, time range relationship is often used to query data within a period of time, such as querying sales records, user activity records, etc. within a certain period of time. There are three basic situations of time range relationships: 1. Inclusion relationship

See all articles