PHP date & time function | find current date & time with diff format

Whatsapp

https://www.fundaofwebit.com/post/php-date-and-time-function-and-find-current-date-and-time-with-diff-format

PHP date & time function | find current date & time with different format


In this post, we are going to learn how to use data and time function in php, where you will see the today DATE and TIME. and also, we will be learning about how to find the current date and time with different FORMAT Types.

So guys, Lets get started to work with this date and time functions in php or to display date and time in different formats:


Step 1: Create a file named index.php and paste the following code as below:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Funda of Web IT</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <div class="card mt-5">
                    <div class="card-header">
                        <h4>How to Date and Time Function (get current Date Time) & show in different FORMAT in PHP</h4>
                    </div>
                    <div class="card-body">
                       
                        <?php date_default_timezone_set('Asia/Kolkata'); ?>

                        <!-- Current Date -->
                        <h4>Current Date:  <?= date('Y-m-d'); ?> </h4>
                        <h5> C-Year: <?= date('Y'); ?></h5>
                        <h5> C-Month: <?= date('m'); ?></h5>
                        <h5> C-Date: <?= date('d'); ?></h5>

                        <hr>

                        <!-- Current Time -->
                        <h4>Current Time:  <?= date('h:i:s A'); ?> </h4>
                        <h5>Hour: <?= date('h'); ?></h5>
                        <h5>Minute: <?= date('i'); ?></h5>
                        <h5>Seconds: <?= date('s'); ?></h5>
                        <h5>AM/PM: <?= date('a'); ?></h5>

                        <hr>

                        <!-- Date Format -->
                        <?php
                            $date = "2021-03-25";
                        ?>
                        <h4>Date Format for : <?= $date?></h4>
                        <h5><?= date('d-m-Y'strtotime($date)); ?></h5>
                        <h5><?= date('d/m/Y'strtotime($date)); ?></h5>
                        <h5><?= date('d:m:Y'strtotime($date)); ?></h5>
                        <h5><?= date('m-d-Y'strtotime($date)); ?></h5>

                        <!-- Time Format -->
                        <hr>
                        <?php
                            $time = "01:10 PM";
                        ?>
                        <h4>Time Format for :  <?= $time?></h4>
                        <h5>  <?= date('h:i A'strtotime($time)); ?> </h5>
                        <h5>  <?= date('h:i'time()); ?> </h5>

                        <h5> Time for 12 Hour Format: <?= date('h:i A'strtotime($time)) ?> </h5>
                        <h5> Time for 24 Hour Format: <?= date('H:i'strtotime($time)) ?> </h5>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>



Thanks for reading...

© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT