Here we are going to learn third step towards PHP. PHP for beginners – Chapter 3.
How to run a sample “hello world” code. Is there any server or compiler required for that?
I hope you have read PHP for beginners – Chapter 1 and PHP for beginners – Chapter 2 before reading this Chapter. In this chapter you will know how to run your code.
Once you have written you code. It is very important to run code. To run code, we need to start Apache server. You have to install Wamp or Xampp server for this.
I will explain you this in Xampp server.
Open Xampp Control Panel. You will see as per following image.
Click on Start button in row of Apache Module. It will start Apache Server. To check it is working proper or not open your browser and type http://localhost
If it will run successful then it will display following page.
This is indicating that you have successfully install xampp control panel. Now you are ready to play with PHP.
Learning any language is easy, if approach to learn language is correct.
You must have knowledge of flow statement (loops – if else,while,for etc.,) , arrays, structures (stack etc., ) to use. They are irrelevant to language.
To lean any language, following thing to you need to know.
- How many software are required?
- How to write a code? Means you need to know about editor in which you can make a code.
- How to run a sample “hello world” code. Is there any server or compiler required for that?
- Syntax of the language.
- Make a simple examples like printing a lines, use Loops, use arrays, use structures.
- One file handling program.
- Session management (if exists in language).
- Database Connections. (Very important)
If you use this approach to learn any language. You can easily understand the language and learn language.
So we will start with this approach and you will able to built a PHP script by yourself.
Click here to Start with PHP for beginners – Chapter 1
Hello, Today we are going to code how to get duration between two dates and time in PHP.
1. Duration between two dates.
Suppose we have two dates. Two get duration between two dates, we first need to convert date in to time stamp using function strtotime. then we will minus one date from another date.
$date1 = “01/01/2018”;
$date2 = “17/01/2018”;
$date1 = strtotime($date1);
$date2 = strtotime($date2);
$dateDiff = $date2 – $date1;
$duration = floor($dateDiff / (60 * 60 * 24));
2. Duration between two times.
Suppose we have two times. Two get duration between two times, we first need to convert time in to time stamp using function strtotime. then we will minus one time from another time.
$time1 = “13:00”;
$time2 = “17:00”;
$time1 = strtotime(date(“Y-m-d”) . ” ” . $time1);
$time2 = strtotime(date(“Y-m-d”) . ” ” . $time2);
$duration = round(abs($time2 – $time1) / 60, 2);