SEC S20W6 || Date & Time Types And String Predefined Methods in PHP

Hello everyone! I hope you will be good. Today I am here to participate in the contest of @kouba01 about the Date & Time Types And String Predefined Methods in PHP. It is really an interesting and knowledgeable contest. There is a lot to explore. If you want to join then:



Join Here: SEC S20W6 || Date & Time Types And String Predefined Methods in PHP




Blue Modern Project Presentation.png

Designed with Canva

Here are the correct answers with explanations:

  1. What does the checkdate function do in PHP?

    • Correct Answer: B. It checks if a date is valid based on the day, month, and year.
    • Explanation: The checkdate function in PHP is used to verify if the provided day, month and year constitute a valid date. It returns true if the date is valid and false otherwise. This is useful for ensuring the validity of a date before performing further operations.
  2. What does the date function return if no timestamp is provided?

    • Correct Answer: A. The system's current date and time as a formatted string.
    • Explanation: When no timestamp is provided the date function in PHP returns the current date and time based on the system’s settings. We can specify a format for how the date and time should be outputted.
  3. Which of the following is true about the mktime function in PHP?

    • Correct Answer: B. It generates a timestamp based on provided hour, minute, second, day, month, and year values.
    • Explanation: The mktime function creates a Unix timestamp for a specific date and time which is determined by the provided values for the hour, minute, second, day, month, and year. If any value is omitted it defaults to the current time.
  4. What is the purpose of the strtotime function in PHP?

    • Correct Answer: B. It converts an English date string into a Unix timestamp.
    • Explanation: The strtotime function parses a string representing a date or time and converts it into a Unix timestamp. It is the number of seconds since January 1, 1970 (the Unix Epoch). This is useful for converting human readable date formats into a format that PHP can manipulate programmatically.


1. Solution


image.png

2. Solution


image.png

3. Solution


image.png

4. Solution


image.png

5. Solution


image.png

6. Solution


image.png

7. Solution


image.png



Project

A- Creation of the Database


image.png

  • Client table

CREATE TABLE Client (
Ncin CHAR(8) PRIMARY KEY,
Name VARCHAR(20),
FirstName VARCHAR(20),
PhoneNumber CHAR(8)
);

  • Equipment table

CREATE TABLE Equipment (
Ref CHAR(5) PRIMARY KEY,
Label VARCHAR(30),
HourlyPrice INT,
Available CHAR(1) CHECK (Available IN ('O', 'N'))
);

  • Rental table

CREATE TABLE Rental (
NcinClient CHAR(8),
RefEquipment CHAR(5),
DateRent DATETIME,
DateReturn DATETIME,
PRIMARY KEY (NcinClient, RefEquipment, DateRent),
FOREIGN KEY (NcinClient) REFERENCES Client(Ncin),
FOREIGN KEY (RefEquipment) REFERENCES Equipment(Ref)
);

I have created these tables by executing SQL Queries separately for each table. And you can see all the tables have been added into the database.

  • Insertion of Records into the Equipment Table

INSERT INTO Equipment (Ref, Label, HourlyPrice, Available)
VALUES
('Jsk01', 'Jet-Ski', 25, 'O'),
('Pch76', 'Parachute', 15, 'N'),
('Ped01', 'Individual Pedal Boat', 10, 'N'),
('Ped02', 'Double Pedal Boat', 18, 'O');

Here you can see that all the records have been added into the Equipment table. I have run SQL query to insert records in the equipment table.

  • Insertion of the four records of choice in Client table.

INSERT INTO Client (Ncin, Name, FirstName, PhoneNumber)
VALUES
('12345678', 'Doe', 'John', '12345678'),
('23456789', 'Smith', 'Jane', '23456789'),
('34567890', 'Brown', 'James', '34567890'),
('45678901', 'Wilson', 'Emily', '45678901');

As it was said that we can add any data of four records of our choice. Here you can see I have added the data in the Client table through SQL query and the data has been updated successfully in the table. And now NCIN from this data will be used for the equipment rental.

B- Creation of Web Documents

As the database work has already completed so now I am going to create web documents to display the data on the web browser and test the functionality.

  • Index.html

    image.png
  • Location.html

    image.png
  • Location.php

    image.png
    image.png
  • Return.html

    image.png
  • Retour.php

    image.png

I have created all the required files for the project. Some are the html files and some are php files. Each file has its own purpose and importance.

In this video I have explained all the working of the website by performing all the tasks practically. I tried different values of NCIN and when the id was wrong the website did not allowed to perform the action. And similarly when the id was correct but the equipment was not available then the system responded me that the equipment is not available. It only allowed to get an equipment on rent when the NCIN or id number was correct and the equipment was available for the rent. And it was adding all the records on the statistics page. Statistics page has date of rental, return date, hourly price, duration and all the price for the total duration of rent.

It was really amazing to develop the project mainly by the string, date and time as well as PHP concepts.


I invite @sualeha, @ngoenyi, @pandora2010 to join this contest.