0% found this document useful (0 votes)
12 views22 pages

6 Dates

The document explains how to use PHP's time() function to get the current timestamp, which is the number of seconds since January 1, 1970. It highlights the advantages of using timestamps for date arithmetic and introduces the DateTime object for managing date and time information from databases. Several tasks are outlined for practical application, including displaying the current date and calculating intervals between dates.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views22 pages

6 Dates

The document explains how to use PHP's time() function to get the current timestamp, which is the number of seconds since January 1, 1970. It highlights the advantages of using timestamps for date arithmetic and introduces the DateTime object for managing date and time information from databases. Several tasks are outlined for practical application, including displaying the current date and calculating intervals between dates.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Getting the Date with

time()(timestamp)
• PHP’s time() function returns
current timestamp, giving us all
the information we need about
the current date and time.

• It requires no arguments and
returns an integer.
p
TASK # 61 – Getting Time() Worksho
Type the following code
Discuss the output
• The integer returned by time()
represents the number of seconds
elapsed since midnight GMT on January
1, 1970.

• The number of seconds that have


elapsed since then is referred to as a
timestamp.
Why
tim e s ta m p
ra th e r t h a n a
sim p l e d ate ?
• From just one number, you can extract
enormous amounts of information.

• A timestamp can make date


arithmetic much easier. Read the
example ….
• Imagine it’s 31 Dec, 1999. Then, you
would have to change day, month and
year to set the date to next day.

• With timestamp, you just have to


add one day’s worth of seconds
(60*60*24, or 86400) to your
current figure.
p
TASK # 62 – Accessing Date info with getDate() Worksho
1. Type the following code
2. Discuss the output
p
TASK # 63 – Worksho

1. Type a PHP script to display today’s date as


follows :

2. Today is : 31 December, 2021, Wednesday.


DateTime object
p
TASK # 64 – Using Date time object to get current date Worksho

1. Type the code Execute

u s in g the
Try s given
e t e r
param ext slides
n
on the at date
to form s
time
DateTime object
DateTime object

Why do we need to construct a DateTime object ?

• We are required to construct a DateTime object


to contain the information of type date or time
retrieved from a database.

• For example, date on which a book was


issued to a library member.

• The date on which a customer purchased a


product.
p
TASK # 65 – Constructing a Date Worksho

1. Type the code Execute


TASK # 66 – Calculate the interval between two dates and format
the result p
Type the code Execute Worksho
TASK # 67 – Calculate the difference in days, month and year
Type the code Execute
p
Worksho
p
TASK # 68 – Worksho

1) Type a script to accept the user’s date of birth. (You


can use “<input type=“date”….) HTML form control.

2) Show the user’s date of birth as given below:


“You were born on : 14-Feb-2001”

3) Show today’s date below date like :


“Today is : 24-Jun-2022”

4) Show how old the user is as given below :


“You are : 17 years, 1 month, 14 days old”

Solution on the next slide


p
SOLUTION 68 – Worksho

You might also like