Q:

PHP find output programs (Date and Time) | set 1

belongs to collection: PHP Find Output Programs

0

Find the output of PHP programs | Date and Time | Set 1: Enhance the knowledge of PHP Date and Time concepts by solving and finding the output of some PHP programs.

Question 1:

<?php
    $today = date("Y#m#d");
    
    printf("Today's Date  %s", $today);
    echo '<br>';
    
    $today++;
    printf("Tomorrow's Date  %s", $today);
?>

Question 2:

<?php
    $cur_time = date("h:i:s");
    printf("%s", $cur_time);
    echo '<br>';
    
    $cur_time++;
    printf("%s", $cur_time);
?>

Question 3:

<?php
    $var = date("a");
    
    $var++;
    
    echo $var;
?>

Question 4:

<?php
    date_default_timezone_set("Asia/Kolkata");
    
    $time = date("h:i:sa");
    
    echo $time;
?>

Question 5:

<?php
    $newdate = mktime(10, 14, 54, 6, 21, 2020);
    echo "Date : " . date("Y-m-d h:i:sa", $newdate);
?>

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer1:

Output:

Today's Date 2021#01#26
Tomorrow's Date 2021#01#27

Explanation:

In the above program, we created a variable $today, which is initialized with the value returned by date() function.

The date() function will return current date. Here, we used characters to represent year, month, and date.

Here 'Y' will represent the current year 2020, 'm' represent month number '06', and' represent the date that is '21', And, we used symbol '#' to separate date, month, and year.

printf("Today's Date  %s",$today);

The printf() will print today's date, and then we used increment operator to increase date, then it will print tomorrow's date.

Answer 2:

Output:

03:19:53
03:19:54

Explanation:

In the above program, we created a variable $cur_time, which is initialized with the value returned by date() function.

The date() function will return current time. Here, we used characters to represent the hour, minute, and second.

Here 'h' will represent current year 03, 'i' represent minutes '19', and 's' will represent seconds that is '53', And we used symbol ':' to separate hour, minute, and second.

printf("%s",$cur_time);

The printf() will print the current time, and then we used increment operator to increase one second, then it will print increased time.

Answer 3:

Output:

an

Explanation:

The above program will print "an" on the webpage, the below statement will return meridiem name in lowercase,

$var = date("a");
  • "AM" - Ante meridiem
  • "PM" - Post meridiem

Then we used increment operator with $var, then it will print "an", and it will print "pn" for "pm".

Answer 4:

Output:

09:46:44am

Explanation:

In the above program, we set time-zone "Asia/Kolkata", And the date() function will return current time, and assigned to variable $time. Then we will print variable $time that will print "09:46:44am" on the webpage.

Answer 5:

Output:

Date : 2020-06-21 10:14:54am

Explanation:

In the above program, we used the mktime() function, which is used to create a date with specified values.

The syntax of mktime() given below:

mktime(hour, minute, second, month, day, year);

Here, newly created date assigned to $newdate then we printed the value of $newdate on the webpage.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP find output programs (define Constant) | set 1... >>
<< PHP find output programs (Math Functions) | set 2...