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

Assalamualaikum my fellows I hope you will be fine by the grace of Allah. Today I am going to participate in the steemit engagement challenge season 20 week 6 by @kouba01 under the umbrella of steemit team. It is about Date & Time Types And String Predefined Methods in PHP. Let us start exploring this week's teaching course.

Green Tosca Modern Geometric Web Hosting Service Presentation.png

Made with Canva

Multiple Choice Quiz

1. What does the checkdate function do in PHP?

  • A. It formats a date into a specific string.
  • B. It checks if a date is valid based on the day, month, and year.
  • C. It returns the current timestamp.
  • D. It adds a period to a date field.

B. It checks if a date is valid based on the day, month, and year.

Explanation: The checkdate function verifies whether the provided day, month, and year form a valid date. For example, it will return false for February 30th, as this date does not exist.


2. What does the date function return if no timestamp is provided?

  • A. The system's current date and time as a formatted string.
  • B. The time elapsed since 1970 in seconds.
  • C. The timestamp for midnight of the current day.
  • D. A boolean value indicating whether the current date is valid.

A. The system's current date and time as a formatted string.

Explanation: If the date function is called without a timestamp, it uses the current date and time of the server by default. The format specified in the function’s parameters is applied to this current date and time.


3. Which of the following is true about the mktime function in PHP?

  • A. It returns the current system timestamp.
  • B. It generates a timestamp based on provided hour, minute, second, day, month, and year values.
  • C. It checks the validity of a date.
  • D. It converts a timestamp into a human-readable string.

B. It generates a timestamp based on provided hour, minute, second, day, month, and year values.

Explanation: The mktime function is used to create a Unix timestamp from specified date and time components. If any of these components are omitted, they default to the current values.


4. What is the purpose of the strtotime function in PHP?

  • A. It formats a date according to a specific format.
  • B. It converts an English date string into a Unix timestamp.
  • C. It compares two date strings.
  • D. It checks if a date is in the future.

B. It converts an English date string into a Unix timestamp.

Explanation: The strtotime function takes a string representation of a date and time and converts it into a Unix timestamp. This is particularly useful for parsing human-readable date formats.

String Functions

  • Question 1


    image.png

  • Question 2


    image.png

  • Question 3


    image.png

  • Question 4


    image.png

  • Question 5


    image.png

Here I have split the string for the ease of visual representation because my screen was not enough to capture the code and output without splitting it. But the main functionality is executed.

  • Question 6


    image.png

  • Question 7


    image.png


A- Creation of the Database

I am using local server via XAMP. For the creation of the database in my local storage I have start Apache and MySQL.


image.png

To open the database I have accessed it through http://localhost/phpmyadmin/. It opened the database linked with my XAMP server.

EquipementLeisure database creation manually.


image.png

  • Client Table
    image.png
  • Equipment Table
    image.png
  • Rental Table
    image.png

  • Insert four records of your choice into the Client table.
    image.png
    image.png

  • Insert the following rows into the Equipment table:
    image.png
    image.png

  • The Client table has customer information such as Ncin, name, and phone number.

  • The Equipment table has equipment data. It has a check constraint on the "Available" field to accept only 'O' or 'N' values.

  • The Rental table links clients and equipment along with the rental and return dates.


B- Creation of Web Documents

  • index.html Page
    image.png

I have divided all the space of the page according to the required layout and design. Zone 1 is for the header, zone 2 is for the links. Zone 3 is for the display of the content. Zone 4 is for the footer.

  • Creation of the form on the "Location.html" page.
    image.png

I have created this form in location.html and all the input fields are required. If the user does not fill the fields, then he will not be able to submit it.

  • Validation Script of PHP at location.php
    image.png
    image.png

  • Creation of the form on the "Return.html" page.
    image.png

  • Validation Script of PHP at Retour.php.php
    image.png
  • Creation of the page "Statistics.php"
    image.png
    image.png
    image.png

I have just shared all the html and PHP pages and the main file of CSS is excluded which was used to manage the design and layout of the page.

In this video I have explained everything. I have added items to the rent. Those were also added in the Statistics page. And if an item is not available then we cannot get that item for rent. If we enter wrong Ncin then the system restricts us by showing an error message of incorrect Ncin. Moreover you can check all the functionality in the video.

I am inviting @chant, @nancy and @otisbrown in this last week of Engagement Challenge.