Search
 
SCRIPT & CODE EXAMPLE
 

PHP

date and time syntax

<?php
 
  /* This answer is about date and time
 
  The syntax for date and time is:
  */
 
  date(format,timestamp)
 
  /* Here, format is required and it specifies the format of the timestamp,
  while timestamp is optional and specifies a timestamp. Default value
  for timestamp is current date and time */
 
  #Some characters that are commonly used for dates are:
  
  l (Lowercase L) - Represents day of the week
  d - Tells the day of the month
  m - Tells the month of the year
  Y - Represents a year
  
  echo "Today is " . date("m/d/Y") . "<br>";
  echo "Today is " . date("m.d.Y") . "<br>";
  echo "Today is " . date("m-d-Y") . "<br>";
  echo "Today is " . date("l");
  
  #Some characters that are commonly used for time are:

  H - 24-hour format of an hour (0 to 23)
  h - 12-hour format of an hour (0 to 12)
  i - Minute with leading zeros (0 to 59)
  s - Seconds with leading zeros (0 to 59)
  a - am or pm
    
  echo "The time is " . date("h:i:sa");
  echo "The time is " . date("H:i:s");

  #Set timezones

  date_default_timezone_set("America/New_York");

  #You can access every timezone here: https://www.php.net/manual/en/timezones.php

  #The timezone by default is UTC

  #mktime()

  mktime(hour, minute, second, month, day, year) #Syntax
    
  $d=mktime(01, 1, 1, 1, 01, 0001);
  echo "Created date is " . date("Y-m-d h:i:sa", $d);

  #strtotime
  
  $d=strtotime("4:33am December 6 2011");
  echo "Created date is " . date("Y-m-d h:i:sa", $d);

  $d=strtotime("tomorrow");
  echo date("Y-m-d h:i:sa", $d) . "<br>";

  $d=strtotime("next Saturday");
  echo date("Y-m-d h:i:sa", $d) . "<br>";

  $d=strtotime("+3 Months");
  echo date("Y-m-d h:i:sa", $d) . "<br>";

  strtotime(time, now) #Syntax
    
  #Due to limitations, there is another page for every other thing of Date and Time
    
  #Search "Date and Time PHP Continued"  
  
?>
Comment

PREVIOUS NEXT
Code Example
Php :: time characters php 
Php :: how to filter laravel eloquent 
Php :: Try raising max_execution_time setting in php.ini file (CentOS path is /etc/php.ini): max_execution_time = 300Fix 504 Gateway Timeout using Nginx 
Php :: js php number format space 
Php :: laravel admin multi images 
Php :: hex2bin (PHP 5 = 5.4.0, PHP 7, PHP 8) hex2bin — Decodes a hexadecimally encoded binary string 
Php :: laravel migration int length 
Php :: on keyup jquery for search php on basis of class name 
Php :: htaccess new date timestamp 
Php :: vindecoder.eu php 
Php :: PHP OOP - Destructor 
Php :: silverstripe image upload field 
Php :: check if any values are the same in an array php 
Php :: pregmatch php only numbers and comma and dot 
Php :: laravel date format valdiate 
Php :: jwt return true 
Php :: intellisense in visual studio code for php-oop 
Php :: laravel digits between does not working 
Php :: activerecord yii2 select with limit(start,end) not working 
Php :: laravel OrderBy on Eloquent whereHas relationship 
Php :: How to Delete Multiple Records using Checkbox in Laravel 
Php :: php declare variable 
Php :: php ifelse 
Php :: pre_get_posts order by title 
Php :: php current page 
Php :: Route pattern cannot reference variable name more than once. laravel 
Php :: How to execute “php artisan migrate” and other Laravel commands in remote server? 
Php :: Laravel Google Line Chart 
Php :: php get time past midnight 
Php :: get the user detail inside the constructor Laravel 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =