ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
For date and time function we know first few things in our
mind
Date and time function
Capital S Year Day Month
Th,rd,st y¡ª17 d=06 m=03
Example--1st Y¡ª2017 n= 6 M=mar
l= Monday,tue.... F=march
D=Mon J=3
By using
[date_default_timezone_get();
using this function we can get the
time which is by default set.
date_default_timezone_set(¡°Asian/Calcutt
a¡±);
By using this function we can get the
current time of the current city or
country.
To set the time
? date_default_timezone_set(¡°Asian/Culcu
tta¡±);
? Echo date(¡°h:i:s a); date(h:i:s A);
? Date(h:i:p); date(h:i:s P);
? Am-anti mariadian
? Pm-post mariadian
Define the time
? G-24hr-1,2,3,4,5---------13,14,15,--------
22,23
? H-24hr-01,02,03,04,05----13,14,15------
22,23
? g-12hr-1,2,3,4,5,--------11,12,1,2,3,-------11
? h-12hr-01,02,03-----11,12,01,02,03-------11
? date_default_timezone_set(¡°Asian/Calcutta¡±)
;
? echo date(¡°d,l,F,y,g:i:s a¡±);
? Output- 06,Monday,March,17 10:58:06 am
Example
We also get output like below
? echo date(todayis l);
? Output---today is Monday
? echo ¡°today is ¡°.date(¡°l¡±);
? Output---today is Monday
echo time();
? By using this function we can get the number
of seconds and we can also call it as unix
timestamp. (1971-2017(or current time))
? echo (time()-1296000); 129600 is 15 days sec
? echo date(¡°y-m-d h:i:s a¡±,(time()-+1296000));
? o/p-17-02-19 11:10:50am (15 day back if -
1296000) or +1296000 then its (17-03-21
11:10:51)
Strtotime();
using this function we can get
the time of befor or after any
year (like 10 years ,20 years
before or after)
? strtotime(-10 years);
? strtotime(+20 years);
Example-difference between the date or years
? $birth=¡°1990-02-12¡±;
? $past=strtotime($birth);
? $curr=time();
? echo(($curr-$past)/(86400*365)); year
? 86400 is seconds for a day
? echo(($curr-$past)/(86400*30)); month
? echo(($curr-$past)/(86400*7)); week

More Related Content

PHP Date and Time Function

  • 1. For date and time function we know first few things in our mind Date and time function Capital S Year Day Month Th,rd,st y¡ª17 d=06 m=03 Example--1st Y¡ª2017 n= 6 M=mar l= Monday,tue.... F=march D=Mon J=3
  • 2. By using [date_default_timezone_get(); using this function we can get the time which is by default set. date_default_timezone_set(¡°Asian/Calcutt a¡±); By using this function we can get the current time of the current city or country.
  • 3. To set the time ? date_default_timezone_set(¡°Asian/Culcu tta¡±); ? Echo date(¡°h:i:s a); date(h:i:s A); ? Date(h:i:p); date(h:i:s P); ? Am-anti mariadian ? Pm-post mariadian
  • 4. Define the time ? G-24hr-1,2,3,4,5---------13,14,15,-------- 22,23 ? H-24hr-01,02,03,04,05----13,14,15------ 22,23 ? g-12hr-1,2,3,4,5,--------11,12,1,2,3,-------11 ? h-12hr-01,02,03-----11,12,01,02,03-------11
  • 5. ? date_default_timezone_set(¡°Asian/Calcutta¡±) ; ? echo date(¡°d,l,F,y,g:i:s a¡±); ? Output- 06,Monday,March,17 10:58:06 am Example
  • 6. We also get output like below ? echo date(todayis l); ? Output---today is Monday ? echo ¡°today is ¡°.date(¡°l¡±); ? Output---today is Monday
  • 7. echo time(); ? By using this function we can get the number of seconds and we can also call it as unix timestamp. (1971-2017(or current time)) ? echo (time()-1296000); 129600 is 15 days sec ? echo date(¡°y-m-d h:i:s a¡±,(time()-+1296000)); ? o/p-17-02-19 11:10:50am (15 day back if - 1296000) or +1296000 then its (17-03-21 11:10:51)
  • 8. Strtotime(); using this function we can get the time of befor or after any year (like 10 years ,20 years before or after) ? strtotime(-10 years); ? strtotime(+20 years);
  • 9. Example-difference between the date or years ? $birth=¡°1990-02-12¡±; ? $past=strtotime($birth); ? $curr=time(); ? echo(($curr-$past)/(86400*365)); year ? 86400 is seconds for a day ? echo(($curr-$past)/(86400*30)); month ? echo(($curr-$past)/(86400*7)); week