PHP Date And Time Functions In Hindi

📔 : PHP 🔗

पिछले Topic में हमने  PHP में date / time के बारे में पढ़ा , इस topic  में  हम PHP में Generally use होने  वाले date / time functions के बारे में पढ़ेंगे।

PHP हमें ऐसे बहुत से predefined functions provide करती है जिनका use करके हम date / time को आसानी से handle कर सकते हैं।

  1. date_default_timezone_set(timezone)
  2. checkdate(int $month, int $day, $year)
  3. getdate()
  4. strtotime($date or $time)
  5. time()
  6. date_default_timezone_set

PHP date_default_timezone_set Function

date_default_timezone_set() function default timezone set करने के लिए उसे किया जाता है , आप अपने timezone के हिसाब से सेट कर सकते हैं।

File : date_time_fun.php

Copy Fullscreen Close Fullscreen
  echo "Current Date Time : ".date("d/M/Y h:i:s A");
Current Date Time : 11/Sep/2020 06:22:00 PM

PHP checkdate Function

checkdate() function check करता है कि दी गयी date valid है या नहीं।

File : date_time_fun1.php

Copy Fullscreen Close Fullscreen
  if(checkdate(12,31, 2303))
    echo "Date is Valid";
    echo "Date is Not valid";
Date is Valid

PHP getdate Function

getdate() function हमें date - time information का एक array return करता है।

File : date_time_fun2.php

Copy Fullscreen Close Fullscreen
    [seconds] => 12
    [minutes] => 47
    [hours] => 17
    [mday] => 11
    [wday] => 5
    [mon] => 9
    [year] => 2020
    [yday] => 254
    [weekday] => Friday
    [month] => September
    [0] => 1599826632

PHP strtotime Function

strtotime() function , किसी English textual date time को UNIX timestamp में convert करता है ।

File : date_time_fun4.php

Copy Fullscreen Close Fullscreen
  $timestamp = strtotime('2020-12-12');
echo "Timestamp Format : $timestamp";
echo "After Change : ".date('Y-M-d', $timestamp);
/* we can also use now inside strtotime() function*/
echo "Current Date Time : " .date('d-M-Y h:i:s A', strtotime('now')); ?>
Timestamp Format : 1607711400
After Change : 2020-Dec-12
Current Date Time : 11-Sep-2020 06:15:19 PM

PHP time Function

time() function , current UNIX timestamp return करता है जिसे हम strtotime() function() का use करके readable form में change कर सकते हैं।

File : date_time_fun5.php

Copy Fullscreen Close Fullscreen
  $time_stamp = time();
  echo "In Timestamp Format : $time_stamp";
  echo "After change : ".date('h:i:s a', strtotime($time_stamp));
In Timestamp Format : 1599826034
After change : 05:30:00 am

PHP date_default_timezone_get Function

date_default_timezone_get() function , current default timezone return करता है।  

File : date_time_fun6.php

Copy Fullscreen Close Fullscreen
  echo date_default_timezone_get();

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook