A	
  simple	
  PHP	
  exercise	
  on	
  date(	
  )	
  
	
  
Exercise:	
  
Given	
  the	
  following	
  codes:	
  
	
  

To...
 
2. Use	
  the	
  searchbox	
  on	
  the	
  right	
  side,	
  type	
  “date”	
  and	
  click	
  on	
  the	
  “date”	
  
f...
Solution:	
  
	
  

The	
  time	
  now	
  on	
  the	
  server	
  is	
  	
  
<?php	
  
	
  	
  echo	
  date("G:i:s");	
  
?...
Upcoming SlideShare
Loading in...5
×

A simple php exercise on date( ) function

5,782

Published on

A simple step by step guide for beginners on using the PHP date( ) functions. Included a part 2 exercise.

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
5,782
On Slideshare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A simple php exercise on date( ) function

  1. 1. A  simple  PHP  exercise  on  date(  )     Exercise:   Given  the  following  codes:     Today's date is <?php echo date(""); ?> <br> The time now on the server is <?php echo date(""); ?>   Modify  the  code  so  that  you  will  get  the  following  output:     Today's date is Thu, 16-Jan-2014 The time now on the server is 13:12:04       Part  1  Step  by  Step:     Step  1:     From  the  given  information,  we  are  able  to  put  in  the  comma,  the  blank  space   and  the  dashes  into  the  date(  )  function  as  follows:     Today's  date  is     <?php      echo  date("?,    ?-­‐?-­‐?");   ?>     Step  2:  find  the  appropriate  format  to  replace  the  ?     Locate  the  php  Manual  by:     1. Google  “php  manual”  and  click  on  the  appropriate  link:        
  2. 2.   2. Use  the  searchbox  on  the  right  side,  type  “date”  and  click  on  the  “date”   function:       3. Refer  to  the  formats  listed,  such  as:         :     :     :     4. Put  the  above  format  into  the  date(  )  function  and  run  the  code  through  your   XAMPP  or  WAMP  servers:     Today's  date  is     <?php      echo  date("D,    d-­‐M-­‐Y");   ?>     Output:     Today's date is Tue, 21-Jan-2014     Part  2:   Now  try  Part  2  on  your  own.    Answer  on  the  next  page.     The  time  now  on  the  server  is     <?php      echo  date("");   ?>     The time now on the server is 13:12:04        
  3. 3. Solution:     The  time  now  on  the  server  is     <?php      echo  date("G:i:s");   ?>       Extra  –  setting  the  correct  timezone   There  are  two  ways  to  set  the  timezone:     1. Use  the  date.timezone  setting  in  the  php.ini  file  –  this  will  affect  all  php   files.       Change  from  the  default  to  your  own  timezone  eg  Asia/Singapore           2. Use  the  date_default_timezone_set()  function  before  the  date(  )  function–   this  will  only  affect  the  current  file.     Today's  date  is     <?php      date_default_timezone_set("Asia/Singapore");      echo  date("D,    d-­‐M-­‐Y");   ?>  

×