AmitDiwan has Published 10740 Articles

PHP program to compute the execution time of a PHP script

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:51:46

721 Views

To compute the execution time of a PHP script, the code is as follows −Example Live DemoOutputThe execution time of the PHP script is : 1.69 secThe ‘microtime’ function can be used to check the time taken by a PHP script to execute completely. When the code begins execution, the time ... Read More

Implementing incremental search and display the values with a specific number in MySQL?

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:51:42

181 Views

For this, you can use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable (Number varchar(100)); Query OK, 0 rows affected (0.60 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('235678'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('1634990'); ... Read More

How can I implement an interval condition for due dates correctly in MySQL?

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:50:50

144 Views

Let us first create a table −mysql> create table DemoTable (DueDate date); Query OK, 0 rows affected (0.92 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-12'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-04-01'); Query OK, 1 row affected (0.17 ... Read More

PHP program to convert a given timestamp into time ago

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:50:46

987 Views

To convert a given timestamp into time ago, the code is as follows −Example Live DemoOutputThe timestamp to time ago conversion is 10 minutes agoA function named ‘to_time_ago’ is defined that checks the difference between the time passed as parameter to the function and the time function. If this difference is ... Read More

Get a fixed number of results in descending order using a MySQL query

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:49:41

244 Views

For descending order result, use DESC. However, LIMIT is used to get fixed number of records −select *from yourTableName order by yourColumnName DESC LIMIT yourLimitNumber;Let us first create a table −mysql> create table DemoTable (Id int, Name varchar(100)); Query OK, 0 rows affected (0.73 sec)ExampleInsert some records in the table ... Read More

PHP program to calculate the total time given an array of times

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:48:50

2K+ Views

The ‘strtotime’ function can be used to convert the given string into a time format. Let us see an example −Example Live DemoOutputThe total time is :-441915:-12:-58An array that contains time format data is defined and the ‘strtotime´function is used to convert the string into a time format. The ‘foreach’ loop ... Read More

PHP program different ways to generate a random string

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:47:41

423 Views

Using bin2hex functionExample Live DemoOutputThe randomly generated string is : f1db16115fa93b98493d388bA number is defined and the bin2hex function is called on this number. Inside the bin2hex function the ‘random_bytes’ function is called on this number. The generated random string is printed on the console.Using hashing functionExample Live DemoOutputThe randomly generated string using ... Read More

PHP program to generate a numeric one-time password

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:47:16

1K+ Views

To generate a numeric one-time password in PHP, the code is as follows −Example Live DemoOutputThe one time password generated is :52471609A function named ‘generate_otp’ is defined that takes the length as a parameter. This is the length of the password that needs to be generated. A number that contains 0 ... Read More

Round seconds to nearest half minute in MySQL?

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:45:14

372 Views

To round seconds to nearest half minute, use CEILING(). Let us first create a table −mysql> create table DemoTable (secondValue int); Query OK, 0 rows affected (0.64 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values(27); Query OK, 1 row affected (0.24 sec) mysql> insert ... Read More

PHP program to compare float values

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:45:05

172 Views

To compare float values in PHP, the code is as follows −Example Live DemoOutputThe values are not sameThree values are defined that are floating point numbers. The absolute values of these numbers are compared and relevant message is displayed on the console.

Advertisements