How do i convert this 1471323637 into time [duplicate] - php

This question already has answers here:
How to create human readable time stamp?
(6 answers)
Closed 6 years ago.
i'm currently looking at something and it says this.
"last_updated":1471323637
how can i convert that number into a time that I can actually read because at the moment i have no idea what time/date that is.
thank you.

Use FROM_UNIXTIME if you want to convert it to human readable time in MySQL
SELECT FROM_UNIXTIME(1471323637);
And you will get an output like below:
2016-08-16 11:00:37

Try this
echo date('H:i:s d/m/y' ,1471323637);
Output
10:30:37 16/08/16
for more info about date please read http://php.net/manual/en/function.date.php
You can also try this
echo date("g:i a, j M Y" ,1471323637);
Output
10:30 am, 16 Aug 2016

Related

Convert time data into human readable time using PHP [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 2 years ago.
I have a time value in the following data format:
"2020-08-05T11:45:10.3159677Z"
How do I convert it to something human readable, like as follows, using PHP?
Wednesday, August 5, 2020, 11:45 AM
Try this:
echo date("H:i A, F jS, Y", strtotime("2020-08-05T11:45:10.3159677Z"));

how to convert date format in php from an existing format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 2 years ago.
In a database, the date is stored like this: 14 May 2020 22:25
I was wondering, when reading this line from database, and change the output to this: 14-5-2020, is it possible to convert this easily? because sometimes i want to output 14 May 2020 22:25 and sometimes i want to output 14-5-2020. And if is possible, i only want to store 1 format in the database
<?php
$date = DateTime::createFromFormat('d M Y H:i', '14 May 2020 22:25');
echo $date->format('d-n-Y'); //14-5-2020
As mentioned in the comment by #Sammitch, you can use PHP DateTime Class to achieve this.
You can format the Date and Time, once you create it. Be sure to check the format guide. Given below as link.
Useful Links:
Formatting DateTime in PHP
PHP DateTime

change date and time format in php [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I am fetching time and date from MYSQLi using php. For time I am getting default 24 hr format and for date I am recieving format of y/m/d.
I want to get time in 12 hr format.
I want to get date in d/m/y format.
How to do it in php ?
In pure simple php, you can write as follow
Date
echo date('d/m/Y', strtotime($your_date));
Time
echo date('H:i', $your_time);
For the 12 hours, use
echo date('g:i A', $your_time);

Convert string timestamp into unix timestamp in PHP [duplicate]

This question already has answers here:
PHP-MYSQL: Converting Unix Timestamp to DateTime and vice versa
(5 answers)
Closed 6 years ago.
Im currently struggeling with timestamps. I have Googled for a simple answer for this, but cant find any solution for my problem. I want to convert user input into UNIX time. The user inputs for example "26/03/1982", how do I convert this input into UNIX timestamp?
//User input
$birthday = "26/03/1982"; // d/m/y
$birthday = [CONVERTED TO UNIX]
Short and simple question. I will add more if you'd like. Thanks.
Look into the PHP function strtotime:
strtotime — Parse about any English textual datetime description into a Unix timestamp
I'm not sure how well it handles / in dates, but replace them with - and it'll work.
Example
echo strtotime(str_replace("/","-","26/03/1982"));
outputs 385977600 which is the Unix date for Fri, 26 Mar 1982
You may need to set your date_default_timezone for this to work

Convert YYYY-MM-DD date to text [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Numerical Date To Text Date PHP
I'm trying to find a way to convert a date to a more "user-friendly" format.
For example, from 2011-01-05 to Jan 5th, 2011.
I'm sure it's something simple, I just can't seem to find it anywhere. Any ideas?
For the th add the English ordinal Suffix for the day of the month
date("M jS, Y", strtotime("2011-01-05"));
Try this:
date("M j, Y", strtotime("2011-01-05"));
You could use the DateTime class, and call the format function. Then just set up the format using the standard date() format string to output a textual data format.

Categories