Author name: admin

Converting string to Date and DateTime

solution 1. Use strtotime() on your first date then date(‘Y-m-d’) to convert it back: Note: There is a difference between using forward slash / and hyphen – in the strtotime() function. solution 2 Observe the difference between m/d/Y and m-d-Y formats. PHP considers / to mean m/d/Y and – to mean d-m-Y. I would explicitly describe the input format in this case: https://stackoverflow.com/questions/6238992/converting-string-to-date-and-datetime

Correctly determine if the date string is a valid date in that format

You will find the solution to the problem statement: take a string such as 2013-13-01 and tell if it is a valid date or not for the format yyyy-mm-dd? Solution 1 You can use DateTime::createFromFormat() for this purpose: solution 2 Use in a simple way with PHP prebuilt function: https://stackoverflow.com/questions/19271381/correctly-determine-if-date-string-is-a-valid-date-in-that-format

How do I use PHP to get the current year?

Use either date or strftime. In this case, it doesn’t matter as a year is a year, no matter what (unless there’s a locale that formats the year differently). Example Solution 2 Using class member access on instantiation (php>=5.4): https://stackoverflow.com/questions/64003/how-do-i-use-php-to-get-the-current-year/64097#64097

convert time stamp to time ago in php?

You should use the DateTime class to get the difference between 2 times, ie; and then use that difference (which is a DateInterval object, $interval) to find the smallest time difference like this; which should echo (at the time of writing) 13 hours. Another solution Check this function intval()

File Handling in PHP

Because it allows you to read, write, and change files on the server, file management in PHP is a critical part of web development. In this post, we will go over the fundamentals of file handling in PHP as well as the most often used file-handling methods. Opening and Closing Files PHP has various file-related …

File Handling in PHP Read More »

en English
X
Scroll to Top