AmitDiwan has Published 10744 Articles

Select query to display duplicate values with max date

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:53:00

1K+ Views

For this, use GROUP BY and HAVING. Let us first create a table −mysql> create table DemoTable    (    StudentName varchar(100),    DueDate date    ); Query OK, 0 rows affected (0.72 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('John', '2019-01-11'); Query OK, ... Read More

PHP program to compute the execution time of a PHP script

AmitDiwan

AmitDiwan

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

685 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

169 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

126 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

952 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

218 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

377 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

342 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

Advertisements