Date Time Convert in Php - fabulouscode

Tuesday, February 5, 2019

Date Time Convert in Php




Fast Date & Last Current Month::
================================
$firstDayUTS = mktime (0, 0, 0, date("m"), 1, date("Y"));
$lastDayUTS = mktime (0, 0, 0, date("m"), date('t'), date("Y"));

echo $firstDay = date("d-m-Y", $firstDayUTS);
echo '||';
echo $lastDay = date("d-m-Y", $lastDayUTS);
================================
Short Date ...
================================

<?php
$date1=$_POST['date1'];
$date2=$_POST['date2'];
$dateOne = date("Y-m-d", strtotime($date1));
$datetwo = date("Y-m-d", strtotime($date2));
 echo date('m/y', strtotime($date1));
 echo '||';
 echo date('F, Y', strtotime($date1));



$old_date = date('l, F d y h:i:s');              // returns Saturday, January 30 10 02:06:34
$old_date_timestamp = strtotime($old_date);
$new_date = date('Y-m-d H:i:s', $old_date_timestamp); 



// object oriented $date = new DateTime('01/15/2017'); // format: MM/DD/YYYY echo $date->format('U'); // or procedural $date = date_create('01/15/2017'); echo date_format($date, 'U');


$currentDate =  time(); // get current date
echo "It is now: ".date("Y-m-d H:i:s", $currentDate)."\n ";
$date = strtotime(date("Y-m-d H:i:s", $currentDate) . " +1 year"); // add 1 year to current date
echo "Date in epoch: ".$date."\n ";
echo "Readable date: ".date("Y-m-d H:i:s",$date)."\n ";
Other examples:
$date = strtotime(date("Y-m-d H:i:s", $currentDate) . " +1 month"); // add 1 month to a date
$date = strtotime(date("Y-m-d H:i:s", $currentDate) . " +6 months"); // add 6 months
$date = strtotime(date("Y-m-d H:i:s", $currentDate) . " +1 day"); // add 1 day
$date = strtotime(date("Y-m-d H:i:s", $currentDate) . " -12 hours"); // subtract 12 hours
$date = strtotime(date("Y-m-d H:i:s", $currentDate) . " -1 day -12 hours"); // subtract 1 day 





1 comment:

  1. Welcome to my blog and thank you for your interest in writing on my blog as well. Contact me if you want to write on my blog.
    My email: freelancersituhin@gmail.com

    ReplyDelete

I am Safiqul Islam Tuhin