PHP Date And Time In Hindi

📔 : PHP 🔗

वैसे तो PHP हमें बहुत से functions provide कराती है  date और time के लिए but सबसे common और generally सबसे ज्यादा use किया जाने वाला function है date().

 PHP  date() function  हमें readable form में timestamp (date with time) value return करता है according तो parameter .  जिसे हम अपनी need के according customize  भी कर सकते हैं। 

PHP Date And Time Example

date() function का use करके current date और time print कराने की कोशिश करते हैं।

File : date_time.php

Copy Fullscreen Close Fullscreen
<?php
   echo 'Curent date time is : '. date('d-m-y h:i:s a');
?>
Output
Curent date time is : 11-09-20 10:48:50 am

Example में आप जो date function में जो small lettersमें characters use किये गए हैं , इन्ही के according PHP हमें DATE / TIME return करती है। आगे बढ़ने से पहले इनके बारे में थोड़ा जानते है -

CharacterDescription
drepresents days of month (01 to 31)
Drepresents day name of week. (example : Mon, Tues, . . . Sun)
lrepresents day name of week. It works same as 'D' .
mrepresents months year (01 to 12) .
Mrepresents month name of year (Example : Jan , feb, . . . Dec).
yrepresents year in two digits . (Example : 20 , 21..).
Yrepresents year in four digits (Example : 2020 , 2021 ..).
hrepresents hours (01 to 12).
Hrepresents hours (01 to 24).
irepresents minutes.
srepresents seconds.
arepresents am / pm.
Arepresents AM / PM.

नीचे दिए गए examples को आप देखकर समझ सकते हैं कि PHP में किस तरह से Date / Time को handle करते हैं।

See Example

File : date_time2.php

Copy Fullscreen Close Fullscreen
<?php
  echo 'Curent Date : '. date('d/m/y');
  echo 'Curent Date : '. date('D-M-Y');
  echo 'Curent Date : '. date('d.M.Y');
  echo 'Curent Date : '. date('d/m/y');
  echo 'Curent Time : '. date('h:i:s a');
  echo 'Curent Time : '. date('H:i:s A');
  echo 'Curent Time : '. date('h:i:s A');
  echo 'Curent Date Time : '. date('d/M/Y h:i:s A');
?>
Output
Curent Date : 11/09/20
Curent Date : Fri-Sep-2020
Curent Date : 11.Sep.2020
Curent Date : 11/09/20
Curent Time : 04:50:59 pm
Curent Time : 16:50:59 PM
Curent Time : 04:50:59 PM
Curent Date Time : 11/Sep/2020 04:50:59 PM

PHP strtotime Function

इसके अलावा आप predefined date को customize भी कर सकते हैं , इसके लिए PHP ने हमें strtotime() function provide किया है जिसकी help से हम दी गयी date / time को need के according get कर सकते हैं।

See Example

File : date_time3.php

Copy Fullscreen Close Fullscreen
<?php
  $date = '1990-11-23';
  echo "Date : ".date('d/M/Y', strtotime($date));
  echo "Day : ".date('d', strtotime($date));
  echo "Day Name : ".date('D', strtotime($date));
?>
Output
Date : 23/Nov/1990
Day : 23
Day Name : Fri

ऊपर दिए गए example में जिस तरह से हमने दी गयी date में से day / day name / date को extract किया उसी तरह से दिए गए time से भी हम strtotime() function use करके hour या minute extract कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers