GENERAL

WinSock in VB
WinSock multiserver
Java (Pocket PC)
DHTML
CSS
Flash/XML
ASP
PHP
JavaScript
Java
Delphi
RSA
WAP
Java Sockets
Subnetting
RS-232
Zip/UnZip (Java)
Word

Source Code
Pascal
Java
C Programming
Applied PC Interfacing
WinSock client
WinSock server
FTP client
HTTP client
Java client/server
HTTP client
Subnetting in VB
RS-232 in VB
WinSock Multiserver
 Design | SFC | Adv. Sec. | Code | Diary | WWW | Essay | Research

PHP - Date and time

PHP supports a whole host of date operations.

Functions.

The following shows a few examples of date/time functions:

 

Date/time functions in PHP

<?php
$today_us = date("Y-m-d");
$today_uk = date("d-m-Y");
$d_and_t = date("Y-m-d H:i:s (T)");

PRINT "Date (UK): $today_uk";
PRINT "<br>Date (US): $today_us";
PRINT "<br>Date and time: $d_and_t";

$today = getdate();
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];
echo "<br>US Date is: $month $mday, $year";
?>

Executed code

Date (UK): 09-02-2012
Date (US): 2012-02-09
Date and time: 2012-02-09 03:51:47 (GMT)
US Date is: February 9, 2012

The strftime() function can be used to date/time into a given format. The tokens used are:

%a

Abbreviated weekday name according to the current locale

%A

Full weekday name according to the current locale

%b

Abbreviated month name according to the current locale

%B

Full month name according to the current locale

%c

Preferred date and time representation for the current locale

%C

Century number (the year divided by 100 and truncated to an integer, range 00 to 99)

%d

Day of the month as a decimal number (range 01 to 31)

%D

Same as %m/%d/%y

%e

Day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')

%g

 Like %G, but without the century.

%G

The 4- digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead.

%h

Same as %b

%H

Hour as a decimal number using a 24-hour clock (range 00 to 23)

%I

Hour as a decimal number using a 12- hour clock (range 01 to 12)

%j

Day of the year as a decimal number (range 001 to 366)

%m

Month as a decimal number (range 01 to 12)

%M

Minute as a decimal number

%n

Newline character

%p

Either `am' or `pm' according to the given time value, or the corresponding strings for the current locale

%r

Time in a.m. and p.m. notation

%R

Time in 24 hour notation

%S

Second as a decimal number

%t

Tab character

%T

Current time, equal to %H:%M:%S

%u

Weekday as a decimal number [1,7], with 1 representing Monday

%U

Week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week

%V

The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.)

%W

Week number of the current year as a decimal number, starting with the first Monday as the first day of the first week

%w

Day of the week as a decimal, Sunday being 0

%x

Preferred date representation for the current locale without the time

%X

Preferred time representation for the current locale without the date

%y

Year as a decimal number without a century (range 00 to 99)

%Y

Year as a decimal number including the century

%Z

Time zone or name or abbreviation

For example using the %A (to display the current day), %H (to display the current hour), and %M (to display the current minute):

Date/time functions in PHP

<?php
print (strftime("Day is %A, Date: %d-%m-%Y "));
print "<br>";
print (strftime("Time zone is %Z, Time: %H:%M"));

?>

Executed code

Day is Thursday, Date: 09-02-2012
Time zone is GMT Standard Time, Time: 03:51

 

 

 

 
 Design | SFC | Adv. Sec. | Code | Diary | WWW | Essay | Research