Home Backend Development PHP Tutorial The solution to the problem that cf cannot be full screen in win7. How to calculate the time difference in php and MySql

The solution to the problem that cf cannot be full screen in win7. How to calculate the time difference in php and MySql

Jul 29, 2016 am 08:44 AM

Recently, when I was studying my love scarf, I had to calculate the number of days in love. This requires PHP to calculate based on the daily date. Let’s talk about several methods to achieve this kind of date calculation:
(1) It is very easy if you have a database Yes! If it is MSSQL, you can use triggers! Just use the function datediff() that specially calculates the date difference! If it is MYSQL, use the difference between two date fields to calculate the calculation result and save it in another numeric field! It can be called when needed Yes!
(2) If there is no database, you have to use PHP’s time and date function!
The following is the main explanation: Example: Calculate the number of days from May 3, 1998 to 1999-6-5:

Copy Code The code is as follows:


$startdate=mktime("0","0","0","5","3","1998"); $enddate=mktime("0","0 ","0","6","5","1999"); //The obtained value is the total number of seconds from 1970-1-1 to the parameter time. The result is an integer. Then the following code is easy to compile More
$days=round(($enddate-$startdate)/3600/24);
echo $days;


$days is the number of days obtained; if the parameters in mktime() are default, it means using the current Date, so you can calculate the number of days since the date the book was borrowed.
Finally, let’s talk about the SQL calculation method:
DateDiff function
Description: Returns the time interval between two dates.
Syntax:

Copy code The code is as follows:


DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear>)


interval: required. A string expression used to calculate the time interval between date1 and date2. See the Settings section for values.
date1, date2: required. Date expression. Two dates used for calculation.
firstdayofweek: Optional. A constant that specifies the first day of the week. If not specified, it defaults to Sunday. See the Settings section for values.
firstweekofyear: Optional. Constant that specifies the first week of the year. If not specified, it defaults to the week of January 1st. See the Settings section for values. The
interval parameter can have the following values:
yyyy (year), q (quarter), m (month), y (number of days in a year), d (day), w (number of days in a week), ww (week), h (hour), n (minute), s (second)
firstdayofweek parameter can have the following values:
(The following are: constant value description)
vbUseSystem 0 Use the Regional Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
firstweekofyear The parameter can have the following values:
(The following are: constant value description )
vbUseSystem 0 Use the Locale Language Support (NLS) API setting.
vbFirstJan1 1 Starts with the week of January 1st (default).
vbFirstFourDays 2 starts with the first week of the new year having at least four days.
vbFirstFullWeek 3 starts with the first full week of the new year.
Description: The DateDiff function is used to determine the number of specified time intervals that exist between two dates. For example, you can use DateDiff to calculate the number of days between two dates, or the number of weeks between today and the last day of the year.
To calculate the number of days between date1 and date2, you can use "days in year" ("y") or "day" ("d"). When interval is "day of the week" ("w"), DateDiff returns the number of weeks between two dates. If date1 is a Monday, DateDiff counts the number of Mondays preceding date2. This result contains date2 but not date1. If interval is "week" ("ww"), the DateDiff function returns the number of weeks between two dates in the calendar table. Function counts the number of Sundays between date1 and date2. DateDiff will evaluate date2 if date2 is a Sunday, but not date1 even if date1 is a Sunday.
If date1 is later than date2, the DateDiff function returns a negative number. The
firstdayofweek parameter affects calculations using the "w" and "ww" separator symbols.
If date1 or date2 is a date literal, the specified year becomes a fixed part of the date. But if date1 or date2 is enclosed in quotation marks (" ") and the year is omitted, the current year will be inserted every time the date1 or date2 expression is evaluated in the code. This makes it possible to write program code that works for different years.
When interval is "year" ("yyyy"), compare December 31st with January 1st of the next year. Although the difference is actually only one day, DateDiff returns 1 to indicate a difference of one year.
DatePart function
Description: Returns the specified part of the given date.
Syntax:

Copy code The code is as follows:

DatePart(interval, date[, firstdayofweek[, firstweekofyear>)


DatePart: The syntax of the function has the following parameters:
interval: Required. A string expression representing the time interval to be returned. See the Settings section for values.
date: required. The date expression to evaluate.
firstdayof week: Optional. A constant that specifies the first day of the week. If not specified, it defaults to Sunday. See the Settings section for values.
firstweekofyear: Optional. Constant that specifies the first week of the year. If not specified, it defaults to the week of January 1st. See the Settings section for values. The
interval parameter can have the following values:
yyyy (year), q (quarter), m (month), y (number of days in a year), d (day), w (number of days in a week), ww (week), h (hour), n (minute), s (second)
firstdayofweek parameter can have the following values:
(The following are: constant value description)
vbUseSystem 0 Use the Regional Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
firstweekofyear The parameter can have the following values:
(The following are: constant value description )
vbUseSystem 0 Use the Locale Language Support (NLS) API setting.
vbFirstJan1 1 Starts with the week of January 1st (default).
vbFirstFourDays 2 starts with the first week of the new year having at least four days.
vbFirstFullWeek 3 starts with the first full week of the new year (not across years).
Description: The DatePart function is used to calculate dates and return the specified time interval. For example, use DatePart to calculate the day of the week or the current time. The
firstdayofweek parameter affects calculations using the "w" and "ww" interval symbols.
If date is a date literal, the specified year becomes a fixed part of the date. But if date is enclosed in quotation marks (" ") and the year is omitted, the current year will be inserted every time the date expression is evaluated in the code. This way you can write program code that works for different years!

The above introduces the solution to the problem that cf cannot full screen win7. The method of calculating the time difference in PHP and MySql, including the solution to the problem that cf cannot full screen win7. I hope it will be helpful to friends who are interested in PHP tutorials.

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles