Timestamp convert to datetime format

  • 23-04-2022
  • 1010
  • PHP
  • Haresh Chauhan

Php time() function providing timestamp of current date and time since 1970, it is refreshing every second and adding one in timestamp in every second.

In this post we will find the current time and convert into date and time different format, using date() function we will easy to convert timestamp into date time custom format.

Using date() function convert to date time format we need to pass two prams first is custom date format and second is your timestamp what you want to convert. date() function expecting minimum 1 param.

Also date() function default will take current time with the 1st param.

Here below is the time function example.

<?php
  
  $time = time();

  echo $time;   //Output 1650802617
?>

Here below is the date function example.

<?php
  
  // current time 2022-04-24 12:23:48
  $time = date('Y-m-d h:i:s'); 
   
  echo $time; //Output 2022-04-24 12:23:48
?>

But above is the understanding of date() and time() functions.

now we will convert timestamp into specific date time format.

<?php  
  
  $format1 = date('Y-m-d h:i:s',1650802617);
  
  echo $format1; // 2022-04-24 12:16:57
  
  $format2 = date('d-m-Y h:i:s',1650802617);
  
  echo $format2; // 24-04-2022 12:16:57
?>

How to connect database with php application

Here below littel understading of date time format.

  • H : 24 Hours format.
  • h : 12 Hours format.
  • i : Minutes.
  • s : Seconds.
  • a : AM/PM Lowercase.
  • A : AM/PM Uppercase.
  • Y : Long Year - 2022.
  • y : Short Year - 22.
  • m : Months 1 to 12.
  • M : Months Jan to Dec.
  • d : Date of Month 1 to 30.

For make the date and time beautiful you can use -, /, \, : etc.

I hope that this post helpful to you well with date and time functions with example understanding.

Thank you for ready our post


We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :