PHP – Date / Time Functions

When working in any programming language, dealing with dates and time is a simple task. That is, until time zones have to be supported. PHP’s time () function gives you all the information that you need about the current date and time. It requires no arguments but returns an numeric value.

If you will call to time() function which will return a set of numeric values which is difficult to understand. So to make it easy we can have time format along with the date() function.

<?php

$today = date(“d/m/Y”);

echo “Today is “.$today;

?>

We can use different time format with separator like d-m-Y, d.m.Y and so on.

Display Current Date and Time:  We can use the following characters to format the time string:

<?php

echo date(“h:i:s”) . “<br>”;

echo date(“F d, Y h:i:s A”) . “<br>”;

echo date(“h:i a”);

?>

Here h-hour in 12-hour format, H – hour in in 24-hour format, i – minutes, s – seconds, a -am, pm(Lowercase) and  A – Represent AM, PM (Uppercase)

So it is easy to get the current year by putting the following line- <?php echo date(“Y”);?>?>

The PHP time(): The time() function is used to get the current time as a Unix timestamp

Example: 

<?php

$cDate = 1394003958;

echo(date(“F d, Y h:i:s”, $cDate));

?>

Example: To print date like 10 July 2015

<?php

$date1 = date_create(―2016-05-10”);

echo date_format($date1, ‘j-F-Y’);

?>

 Output: 10 May 2016

php classes in gurgaon

Leave a Reply

Your email address will not be published. Required fields are marked *

About Us

Luckily friends do ashamed to do suppose. Tried meant mr smile so. Exquisite behaviour as to middleton perfectly. Chicken no wishing waiting am. Say concerns dwelling graceful.

Services

Most Recent Posts

  • All Post
  • advanced-excel-training
  • Branding
  • deepti saini model
  • Development
  • Digital Marketing
  • digital marketing course gurgaon
  • Digital Marketing Internship Gurugram
  • digital marketing jobs
  • digital-marketing-institutes-sector-14
  • Leadership
  • Management
  • Notice
  • php-development-courses
  • php-full-stack-development-courses
  • php-job-opportunity
  • php-training
  • php-training-in-baksar
  • php-training-in-balia
  • php-training-in-bangalore
  • php-training-in-delhi
  • php-training-in-faridabad
  • php-training-in-gaziabad
  • php-training-in-gorakhpur
  • php-training-in-gurgaon
  • php-training-in-kolkata
  • php-training-in-muzaffarpur
  • php-training-in-noida
  • php-training-in-patna
  • placements
  • web development training gurgaon

Company Info

She wholly fat who window extent either formal. Removing welcomed.

Limited Seats Available – Register Now

We keep batch sizes limited so every learner gets personal attention and proper doubt solving. Reserve your seat now and start your training in the next batch without delay. For details call us +91- 8802000175

Help

Privacy Policy

Terms

Conditions

Subscribe Now

For latest news and updates, fill your details below-

You have been successfully Subscribed! Ops! Something went wrong, please try again.
© 2023 Created with Royal Elementor Addons