Chuyển đổi date thành timestamp trong php

Tutorials Algorithms Analysis of Algorithms Data Structures Languages Interview Corner GATE ISRO CS UGC NET CS CS Subjects website Technologies Student Jobs
*

*

*

*

The DateTime::sub() function is an inbuilt function in PHP which is used to lớn subtract a number of days, months, years, hours, minutes và seconds from a created DateTime object.

Bạn đang xem: Chuyển đổi date thành timestamp trong php

Bạn đang xem: Datetime::sub

Syntax:

Object oriented style:

DateTime DateTime::sub( DateInterval interval )Procedural style:DateTime date_sub( DateTime $object, DateInterval $interval )Parameters: This function uses two parameters as mentioned above and described below:

$object: This parameter holds the DateTime object created by date_create() function.$interval: This parameter holds the DateInterval object.

Xem thêm: Phân Tích An Toàn Công Việc ( Jsa Là Gì ? So Sánh Jsa, Jha Là Gì ?

Return Values: This function returns the DateTime object after subtraction is done on success or False on failure.

Below programs illustrate the DateTime::sub() function in PHP:

Program 1: This program uses DateTime::sub() function to subtract 2 days from given date object.

// PHP program khổng lồ illustrate DateTime::sub() // function // Creating a new DateTime() object // Initialising a interval of 2 days $interval = "P2D"; // Calling the sub() function $datetime->sub(new DateInterval($interval)); // Getting a new date time // format of "Y-m-d" echo $datetime->format("Y-m-d"); ?> Output:Program 2: This program uses DateTime::sub() function lớn subtract the given interval from date object.// PHP program to lớn illustrate DateTime::sub() // function // Creating a new DateTime() object // Initialising an interval $interval = "P2Y5M2DT0H30M40S"; // Calling the sub() function $datetime->sub(new DateInterval($interval)); // Getting a new date time // format of "Y-m-d H:i:s" echo $datetime->format("Y-m-d H:i:s"); ?> Output:Reference: https://www.php.net/manual/en/datetime.sub.php My Personal Notes arrow_drop_up Save favorite_border like first_page Previous How Does NASA Use Machine Learning? Next last_page PLSQL | ABS Function Recommended ArticlesPage : How khổng lồ convert JavaScript datetime khổng lồ MySQL datetime ?27, Jun 19PHP | DateTime setDate() Function10, Oct 19PHP | DateTime modify() Function10, Oct 19PHP | DateTime diff() Function10, Oct 19PHP | DateTime format() Function10, Oct 19PHP | DateTime createFromFormat() Function10, Oct 19PHP | DateTime add() Function10, Oct 19PHP | Converting string lớn Date & DateTime18, Oct 18PHP date() format when inserting into datetime in MySQL02, Jan 19How lớn copy a DateTime object in PHP ?22, Apr 20HTML | DOM input đầu vào Datetime Object11, Feb 19HTML | DOM input đầu vào Datetime min Property20, Feb 19HTML | DOM input đầu vào Datetime max Property20, Feb 19HTML | DOM input đầu vào Datetime disabled Property20, Feb 19HTML | DOM đầu vào Datetime autofocus Property20, Feb 19HTML | DOM input đầu vào Datetime khung Property27, Feb 19HTML | DOM input Datetime readOnly Property27, Feb 19HTML | DOM input đầu vào Datetime name Property27, Feb 19HTML | DOM đầu vào Datetime required Property27, Feb 19HTML | DOM input đầu vào Datetime type Property27, Feb 19HTML | DOM ins dateTime Property01, Mar 19HTML | DOM del dateTime Property28, Mar 19HTML | DOM Time dateTime Property18, Apr 19 datetime Attribute" rel="bookmark" class="c-wrap"> HTML | datetime Attribute29, Apr 19Article Contributed By :
*

Kanchan_Ray Kanchan_Ray Vote for difficulty Easy Normal Medium Hard Expert Report Issue What’s NewData Structures & Algorithms – Self Paced CourseView DetailsAd-Free Experience – obatambeienwasirherbal.com PremiumView DetailsMost popular in PHPMost visited in web Technologies

Writing code in comment? Please use ide.obatambeienwasirherbal.com, generate links and chia sẻ the links here.

Load Comments 5th Floor, A-118, Sector-136, Noida, Uttar Pradesh - 201305 feedbackobatambeienwasirherbal.com Company Learn Practice Contribute obatambeienwasirherbal.com , Some rights reserved We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read và understood our Cookie Policy & Privacy Policy Got It !