Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
How To Change The Date Formate In Php

How to change the date formate in php

Posted on February 20, 2019November 15, 2020 By XpertPhp No Comments on How to change the date formate in php

Today, We are going to how to change the date formate in PHP. when we have to need to change the date format then we are the use of the PHP date format. See below here some example of display the date using the date format.

PHP
1
2
3
4
5
6
7
8
9
<?php
date_default_timezone_set("America/New_York");
echo date("Y-m-d h:i:s");
 
see below output here.
 
2019-02-20 22:05:10
 
?>

See below required specific string character for the date format.

TypeCharacterDescription
Datedday of the month, 2 digits with leading zeros; i.e. ’01’ to ’31’
 jday of the month without leading zeros; i.e. ‘1’ to ’31’
DayDday of the week, textual, 3 letters; i.e. ‘Fri’
 lday of the week, textual, long; i.e. ‘Saturday’
 wday of the week, numeric, i.e. ‘0’ (Sunday) to ‘6’ (Saturday)
 zday of the year; i.e. ‘0’ to ‘365’
 rRFC 822 formatted date; i.e. ‘Thu, 21 Dec 2000 16:01:07 +0200’ (added in PHP 4.0.4)
 SSuffix for day of the month in 2 chrs ( with j )
 zDay of the year ( from 0 to 365 )
Monthmmonth; With leading zeros; i.e. ’01’ to ’12’
 nmonth without leading zeros; i.e. ‘1’ to ’12’
 Mmonth, textual, 3 letters; i.e. ‘Jan’
 Fmonth, textual, long; i.e. ‘January’
 tNumber of days in the month ( 28 to 31 )
YearL1 for Leap year, 0 if not
 oISO-8601 week-numbering year.
 Yyear, 4 digits; i.e. ‘2018’
 yyear, 2 digits; i.e. ’19’
Time
Hourghour, 12-hour format without leading zeros; i.e. ‘1’ to ’12’
 Ghour, 24-hour format without leading zeros; i.e. ‘0’ to ’23’
 hhour, 12-hour format; i.e. ’01’ to ’12’
 Hhour, 24-hour format; i.e. ’00’ to ’23’
Minutesiminutes; i.e. ’00’ to ’59’
Secondssseconds; i.e. ’00’ to ’59’
 a‘am’ or ‘pm’
 A‘AM’ or ‘PM’
 BSwatch Internet time
 I‘1’ if Daylight Savings Time, ‘0’ otherwise.
 Lboolean for whether it is a leap year; i.e. ‘0’ or ‘1’
 TTimezone setting of this machine; i.e. ‘MDT’
 Useconds since the epoch
 Ztimezone offset in seconds (i.e. ‘-43200’ to ‘43200’). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
 e, O, P and Ttimezone identifier ( e ) , difference in Hour and minutes to GMT (O),+- Hour : Minute (P), Short name of zone ( IST) (T)

Most used php date format

1
2
3
4
5
6
7
8
9
10
11
<?php
echo date("F j, Y, g:i a");                 // July 17, 2020, 8:47 am
echo date("m.d.y");                         // 07.17.20
echo date("j, n, Y");                       // 17, 7, 2020
echo date("Ymd");                           // 20200717
echo date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 17th day.
echo date("D M j G:i:s T Y");               // Fri Jul 17 8:48:07 CEST 2020
echo date('H:m:s \m \i\s\ \m\o\n\t\h');     // 09:05:39 m is month
echo date("H:i:s");                         // 08:48:07
echo date("Y-m-d H:i:s");                   // 2020-07-17 08:48:07 (MySQL DATETIME format)
?>

convert datetime string to timestamp php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$time = strtotime("5 months 10 days 8 hours ago");
echo 'It was '.date('l', $time).' on '.date('d F, Y h:i:s', $time).'.';
// Output -  It was Friday on 07 February, 2020 02:09:25.
$time = strtotime("next month");
echo 'It is '.date('l', $time).' on '.date('d F, Y h:i:s', $time).'.';
//Output  -  It is Monday on 17 August, 2020 09:27:27.
$time = strtotime("third monday");
echo 'Date on the third monday from now will be '.date('d F, Y', $time).'.';
// Output -  Date on the third monday from now will be 03 August, 2020.
$time = strtotime("last day of December 2022");
echo 'Last day of December 2022 will be '.date('l', $time).'.';
// Output - Last day of December 2022  will be Saturday.
?>

PHP add 1 day to the current date

1
2
3
4
5
<?php
$today = date('d-m-Y');
$tomorrow = date('d-m-Y', strtotime($today . ' +1 day'));
echo 'date after adding 1 day: ' . $tomorrow;
?>

PHP subtract 1 day to the current date

1
2
3
4
5
<?php
$today = date('d-m-Y');
$yesterday  = date('d-m-Y', strtotime($today . ' -1 day'));
echo 'date after adding 1 day: ' . $yesterday;
?>

PHP add 1 week to the current date

1
2
3
4
5
<?php
$today = date('d-m-Y');
$nextWeek = date('d-m-Y', strtotime($today . ' +1 week'));
echo 'date after adding 1 day: ' . $nextWeek;
?>

PHP subtract 1 week to the current date

1
2
3
4
5
<?php
$today = date('d-m-Y');
$previousWeek = date('d-m-Y', strtotime($today . ' -1 week'));
echo 'date after adding 1 day: ' . $previousWeek;
?>

PHP add 1 month to the current date

1
2
3
4
5
<?php
$today = date('d-m-Y');
$nextMonth = date('d-m-Y', strtotime($today . ' +1 month'));
echo 'date after adding 1 day: ' . $nextMonth;
?>

Subtract 1 month from a given date in PHP

1
2
3
4
5
<?php
$today = date('d-m-Y');
$previousMonth = date('d-m-Y', strtotime($today . ' -1 month'));
echo 'date after adding 1 day: ' . $previousMonth;
?>

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • PHP Ajax Update Data in MySQL By Using Bootstrap Modal
  • Number_format() function in php
  • How to detect Ajax Request in PHP
  • How to upload and resize image in php with example
  • Login with Facebook using PHP
Php Tags:change date formate, current date, date display, date function, date to date, default time zone set, full date, setdate, strtotime to date., timestamp to date

Post navigation

Previous Post: How to check & uncheck a checkbox with jQuery
Next Post: delete a multiple selected rows in PHP without Ajax

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Latest Posts

  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example
  • Laravel 9 Stripe Payment Gateway Integrate Example
  • How To Send Email Using Mailtrap In Laravel 9
  • Laravel 9 Fullcalendar Ajax Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Age Calculator Online
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com