Monthly Archives: December 2017

Fetch all dates between two dates – PHP

When build an event in a calender; we want to fetch all dates between the date using php.
Store the dates into a php variable fromdate and todate. Then we can fetch all dates between these fromdate and todate using for loop in php.



The output is:

2017-12-01

2017-12-02

2017-12-03

2017-12-04

2017-12-05

2017-12-06

Finding the number of days between two dates – PHP

Good Morning to all,
Finding the number of days between two dates is very useful and very important in day to day activity. Its very used in developers for like leave request because we select the date range and stored to database. From the selected data: from date and to date we find the number of days between these selected dates, and stored to database.

There are different methods are available to find the date diffrence between two date. In php date_diff() functions are available to find the date difference.

Method 1: PHP date_diff() Function

Calculate the date diffrence between two date using date_diff() in php. Its very simple method to solve this situations. The date_diff() function returns the difference between two Date. It is the easiest way to calculate the date difference in PHP.This function available from PHP version 5.3.0.

The date_diff() format is: date_diff($date1, $date2);

Example

format("%R%a days");
?>

From the above code we get +5. Store the two date in php variable like $date1 and $date2. And use date_diff() to calculate the difference.

Method 2:


From the above code we get the output 6.

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Download the table content to pdf -PHP

Hi all, After some weeks I came with one important topic, it is very useful to developers. Because nowadays, fetch the table content or html content to pdf and then download the pdf file; its very common in real world.

This topic is already discuss; here I use different method than other. Because HTML or PHP to pdf is not an easy task. So, I try solve this problem very easy method.

There are two important js files are included for solving data to pdf file in php. First we include jquery (normal jquery like jquery10.1, jquery 11) file and second is; another js file related to pdf.

In here we can download specified div. We can download between the div content as you wish. And we can specify the pdf table or content style through script.

Sample Code

Report

Name Sex Hours
Pritty F 20:10:46
Princy F 21:10:46
Prince M 20:10:46

In the above code; we include two js files and we click the button then the html data convert to pdf file and automatically download or save as employee_report.pdf file. I think its very easy to understand.

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.