Category: Programming

Useful GIT Commands

Initiate Git git init Set configuration valuesgit config — global user.name your namegit config — global user.email your email Check current status of Gitgit status Add single file in Gitgit add filename Add all file changes to the staging areagit add . Add all modified / created files in Gitgit add * Check the unstaged changedgit diff […]

Read More

PHP function to get difference between dates

Below is a PHP function that calculates and displays the difference in days between two dates. This function will take two date strings as inputs, convert them to DateTime objects, and then calculate the difference in days. Here’s how you can define and use the function: Explanation: Creating DateTime Objects: new DateTime($date1): This converts the […]

Read More

Generate random number in PHP

In PHP, you can generate a random number between 1 and 9 using the rand() or mt_rand() functions. Here are examples of both: Using rand() Function: $randomNumber = rand(1, 9);echo “Random number between 1 and 9: ” . $randomNumber; Using mt_rand() Function: $randomNumber = mt_rand(1, 9);echo “Random number between 1 and 9: ” . $randomNumber; […]

Read More

Convert Indian currency from numeric to words in PHP

To convert a numeric value to Indian currency format (words), you can use a custom function. Here’s an example of how you can achieve this: This function convertToIndianCurrencyWords() converts a numeric value into its Indian currency format representation in words. Adjust the code as needed for different ranges or specific formatting requirements. The example provided here is […]

Read More

Covert all date data format from VARCHAR to DATE in any MySQL table

Converting varchar data to date format in MySQL involves several steps. Here’s a method to achieve this: Assuming your varchar date column is named date_column and your table is named your_table, you can follow these steps: Remember to take a backup of your data before making such changes to your database. Incorrectly manipulating your database […]

Read More

Export MySQL data into Excel using PHP

To fetch data from a MySQL database and export it to Excel, you can use PHP along with a library like PHPExcel or PHPSpreadsheet (which is the successor of PHPExcel). Here, I’ll provide an example using PHPExcel. Please note that PHPExcel is now deprecated, and PHPSpreadsheet is recommended for new projects. If you’re starting a […]

Read More

How to reverse date in PHP

To reverse the date from the format “yyyy-mm-dd” to “mm-dd-yyyy” in PHP, you can use the following script: In this script, the variable $date holds the original date in the “yyyy-mm-dd” format. The date() function is then used to convert and format the date. By passing the $date variable to strtotime(), it is converted to […]

Read More