- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?
152 Lectures 16 hours
87 Lectures 5.5 hours
The function TIME_TO_SEC() can be used in MySQL. If you want to convert datetime to seconds use the strtotime() from PHP. The MySQL syntax is as follows:
Now you can convert PHP datetime to seconds with the help of strtotime().
First, you need to install XAMPP server to run your PHP program.
After installing XAMPP successfully in C drive, here is the location wherein you need to include the PHP file. The snapshot is as follows:
Note: Here, I have changed port of Apache to 8086 because default port was held by another program. This is done to begin running PHP program.
Therefore, if in your system the default port is working then use it otherwise you can use your updated port in address bar. The url is as follows:
So, here the port number is 8086, ’locationofphpfile’ is ‘phpproject’. Here is the snapshot of port number:
First, open the editor and write the below code to convert datetime to seconds. The PHP code is as follows.
Save the program with .php extension like ‘yourFileName.php’. I have saved with ‘DifferenceInSeconds.php’.
<<?php $MySQLDateTime='2019-01-29 13:50:40'; echo "<h1>The strtotime value is:"."</h1>".strtotime($MySQLDateTime)."<br>"; echo "<h1>The time value is:"."</h1>".time()."<br>"; $diffenceInSeconds = strtotime($MySQLDateTime)-time(); echo "<h1>The difference of both time in seconds is:"."</h1>".$diffenceInSeconds; ?>
The snapshot of PHP code is as follows:
Now open any browser and paste URL in address bar.
The port number is 8086 in my system. Check your port number in XAMPP server. Paste the following url in address bar. Here, the phpproject is our folder in XAMPP/ htdocs/ wherein we have saved our PHP file:
After pressing enter key you will get a page where your program is saved. The snapshot is as follows:
Now click the above php file ‘DifferenceInSeconds.php’. You will get the following output:
- How to convert JS date time to MySQL datetime?
- What is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time in C#?
- What is the PHP stripos() equivalent in MySQL?
- What is the PHP equivalent of MySQL's UNHEX()?
- Convert INT to DATETIME in MySQL?
- MySQL query to convert timediff() to seconds?
- Remove seconds from MySQL Datetime?
- How to convert time seconds to h:m:s format in Python?
- Convert the specified Windows file time to an equivalent local time in C#
- How to convert timestamp to datetime in MySQL?
- How to get the total number of seconds from a MySQL DATETIME instance?
- What is the Certainty Equivalent Method?
- What is the equivalent of EXCEPT in MySQL?
- MySQL Query to convert from datetime to date?
- How to convert MySQL datetime to Unix timestamp?