Practice 50 PHP Date Programming Questions, TechnoVlogs

Practice 50 PHP Date Programming Questions


Q1: Write a program to get the current date in the format "Y-m-d".  
Input: currentDate()  
Expected Output:  
2024-12-29

Q2: Write a function to get the current time in the format "H:i:s".  
Input: currentTime()  
Expected Output:  
14:30:45

Q3: Write a program to add 5 days to the current date.  
Input: addDaysToDate(5)  
Expected Output:  
2025-01-03

Q4: Write a program to subtract 10 days from the current date.  
Input: subtractDaysFromDate(10)  
Expected Output:  
2024-12-19

Q5: Write a function to get the name of the day for a given date.  
Input: getDayName("2024-12-29")  
Expected Output:  
Sunday

Q6: Write a function to get the first day of the current month.  
Input: getFirstDayOfMonth()  
Expected Output:  
2024-12-01

Q7: Write a function to get the last day of the current month.  
Input: getLastDayOfMonth()  
Expected Output:  
2024-12-31

Q8: Write a function to check if a given year is a leap year.  
Input: isLeapYear(2024)  
Expected Output:  
True

Q9: Write a function to calculate the number of days between two dates.  
Input: daysBetweenDates("2024-12-29", "2025-01-10")  
Expected Output:  
12

Q10: Write a function to get the current timestamp.  
Input: getCurrentTimestamp()  
Expected Output:  
1709207845

Q11: Write a program to convert a timestamp into a date.  
Input: timestampToDate(1709207845)  
Expected Output:  
2024-12-29

Q12: Write a program to get the number of days in a specific month and year.  
Input: daysInMonth(2024, 2)  
Expected Output:  
29

Q13: Write a function to format the current date as "d/m/Y".  
Input: formatDateDMY()  
Expected Output:  
29/12/2024

Q14: Write a function to format the current date as "l, F j, Y".  
Input: formatDateLong()  
Expected Output:  
Sunday, December 29, 2024

Q15: Write a program to add 3 months to the current date.  
Input: addMonthsToDate(3)  
Expected Output:  
2025-03-29

Q16: Write a program to subtract 2 months from the current date.  
Input: subtractMonthsFromDate(2)  
Expected Output:  
2024-10-29

Q17: Write a function to get the week number of the current date.  
Input: getWeekNumber()  
Expected Output:  
52

Q18: Write a function to get the difference in hours between two timestamps.  
Input: hoursBetweenTimestamps(1709207845, 1709211445)  
Expected Output:  
1

Q19: Write a function to check if a given date is a weekend.  
Input: isWeekend("2024-12-29")  
Expected Output:  
True

Q20: Write a function to get the quarter of the year for a given date.  
Input: getQuarter("2024-12-29")  
Expected Output:  
4

Q21: Write a program to calculate the age from a given birthdate.  
Input: calculateAge("2000-05-15")  
Expected Output:  
24

Q22: Write a function to find the next Monday from the current date.  
Input: getNextMonday()  
Expected Output:  
2024-12-30

Q23: Write a function to check if a given date is today.  
Input: isToday("2024-12-29")  
Expected Output:  
True

Q24: Write a function to convert a string date from "d-m-Y" to "Y-m-d".  
Input: convertDateFormat("29-12-2024")  
Expected Output:  
2024-12-29

Q25: Write a program to find the number of weeks between two dates.  
Input: weeksBetweenDates("2024-12-01", "2024-12-29")  
Expected Output:  
4

Q26: Write a program to find the number of months between two dates.  
Input: monthsBetweenDates("2024-01-01", "2024-12-29")  
Expected Output:  
11

Q27: Write a function to get the previous Friday from the current date.  
Input: getPreviousFriday()  
Expected Output:  
2024-12-27

Q28: Write a function to calculate the total number of seconds in a day.  
Input: secondsInADay()  
Expected Output:  
86400

Q29: Write a program to find the date of the next leap year.  
Input: getNextLeapYearDate()  
Expected Output:  
2028-02-29

Q30: Write a function to format a date in the format "D, d M Y H:i:s" (e.g., "Sun, 29 Dec 2024 14:30:00").  
Input: formatDateWithTime()  
Expected Output:  
Sun, 29 Dec 2024 14:30:00

Q31: Write a function to check if a given date is in the past.  
Input: isPastDate("2023-12-29")  
Expected Output:  
True

Q32: Write a function to find the time difference in minutes between two times.  
Input: minutesBetweenTimes("14:30:00", "15:00:00")  
Expected Output:  
30

Q33: Write a program to get the timezone of the server.  
Input: getServerTimezone()  
Expected Output:  
UTC

Q34: Write a program to change the timezone to "Asia/Kolkata" and get the current date and time.  
Input: setTimezone("Asia/Kolkata")  
Expected Output:  
2024-12-29 20:00:00

Q35: Write a function to check if two dates fall in the same week.  
Input: isSameWeek("2024-12-29", "2025-01-02")  
Expected Output:  
True

Q36: Write a program to find the number of days left in the current year.  
Input: daysLeftInYear()  
Expected Output:  
2

Q37: Write a function to calculate the UNIX timestamp for the beginning of the day of a given date.  
Input: getStartOfDayTimestamp("2024-12-29")  
Expected Output:  
1709164800

Q38: Write a function to calculate the UNIX timestamp for the end of the day of a given date.  
Input: getEndOfDayTimestamp("2024-12-29")  
Expected Output:  
1709251199

Q39: Write a program to display the current date in the ISO 8601 format.  
Input: getISO8601Date()  
Expected Output:  
2024-12-29T14:30:00+00:00

Q40: Write a function to check if a given date is the first day of the month.  
Input: isFirstDayOfMonth("2024-12-01")  
Expected Output:  
True

Q41: Write a program to find the number of weekdays between two dates.  
Input: weekdaysBetweenDates("2024-12-01", "2024-12-29")  
Expected Output:  
20

Q42: Write a program to find the difference in months and days between two dates.  
Input: differenceInMonthsAndDays("2024-01-15", "2024-12-29")  
Expected Output:  
11 months, 14 days

Q43: Write a function to find the time left until midnight.  
Input: timeUntilMidnight()  
Expected Output:  
09:30:00

Q44: Write a program to find the number of Sundays in a given month.  
Input: countSundays(2024, 12)  
Expected Output:  
5

Q45: Write a function to check if a given date is within the current year.  
Input: isWithinCurrentYear("2024-06-15")  
Expected Output:  
True

Q46: Write a program to calculate the number of years, months, and days between two dates.  
Input: yearsMonthsDaysBetweenDates("2000-01-01", "2024-12-29")  
Expected Output:  
24 years, 11 months, 28 days

Q47: Write a program to format a date in the format "jS F Y" (e.g., "29th December 2024").  
Input: formatDateOrdinal()  
Expected Output:  
29th December 2024

Q48: Write a function to get the timestamp for the last second of the current year.  
Input: getLastSecondOfYear()  
Expected Output:  
1709337599

Q49: Write a function to check if a given date falls on a public holiday (e.g., New Year's Day: 2024-01-01).  
Input: isPublicHoliday("2024-01-01")  
Expected Output:  
True

Q50: Write a program to calculate the time elapsed since a specific date in years, months, and days.  
Input: timeElapsedSince("2000-05-15")  
Expected Output:  
24 years, 7 months, 14 days

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!