Calculate days between two dates in MySQL with example : उदाहरण के साथ MySQL में दो तिथियों के बीच के दिनों की गणना करें

Calculate days between two dates in MySQL

How to Calculate days between two dates in MySQL(MySQL में दो तिथियों के बीच दिनों की गणना कैसे करें) –

The MySQL DATEDIFF() function returns the number of days between the two dates. The DATEDIFF() function takes two arguments/parameters date1 and date2 (MySQL DATEDIFF() फ़ंक्शन दो तिथियों के बीच के दिनों की संख्या लौटाता है। DATEDIFF() फ़ंक्शन दो तर्क/पैरामीटर लेता है: date1 और date2).

  • DATEDIFF(date1, date2)

Example : 1 – In this example, the days are calculated from current date in mySql (इस उदाहरण में, दिनों की गणना वर्तमान तिथि से की जाती है।).

SELECT DATEDIFF(CURDATE(), '2020-02-14');

Example : 2 – In this example, the days are calculated between two dates (इस उदाहरण में, दिनों की गणना दो तिथियों के बीच की जाती है।

).

SELECT DATEDIFF('2020-04-30', '2020-01-01'); // date format Y-m-d

Example : 3 – In this example, the days are calculated between two dates & time of MySQL (इस उदाहरण में, दिनों की गणना MySQL की दो तिथियों और समय के बीच की जाती है).

SELECT DATEDIFF('2020-04-30 10:11:20', '2020-01-01 11:45:22'); // date format Y-m-d h:m:s

Example : 4 – In this example, the total days are calculated between two columns names when column type is ‘datetime‘ in the MySQL table (इस उदाहरण में, जब MySQL तालिका में स्तंभ प्रकार ‘datetime’ है, तो दो स्तंभ नामों के बीच कुल दिनों की गणना की जाती है).

student_experience Table
SELECT DATEDIFF(exp_to_date, exp_from_date) + 1 AS TotalDays FROM student_experience;  // include one day
//Output is 30 days

Example : 5 -In this example, the total days are calculated between two columns names when column type is ‘date‘ in the MySQL table (इस उदाहरण में, जब MySQL तालिका में स्तंभ प्रकार ‘दिनांक’ है, तो दो स्तंभ नामों के बीच कुल दिनों की गणना की जाती है).

student_experience Table
SELECT DATEDIFF(exp_to_date, exp_from_date) + 1 AS TotalDays FROM student_experience;  // include one day
//Output is 30 days

Love Quotes in Hindi …

Calculate days between two dates in MySQL with example

Tags: Calculate days between two dates in MySQL, How to get the number of days of difference between two dates, MySQL DATEDIFF() function

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *