Question

I am taking credit card details and I am taking the expiration date in two form field, one for the expiration month and one for the expiration year, I am wanting to store the expiration date as timestamp. Will strtotime("05/2010") create a time stamp or do I need to pass a day as well or is there an alternative?

Thanks

Was it helpful?

Solution

No, that won't work, strtotime("05/2010") will return false. You would need to specify a day as well. However, there's ambiguity in that case as does strtotime("01/05/2010") mean the 1st of May 2010, or the 5th of January 2010? etc

You're probably better using mktime() instead of strtotime(), since you can explicitly state which parts are the month and year, and then just pass 1 as the day.

$timestamp = mktime(0,0,0,$month,1,$year); // Where $month = 5, $year = 2010

OTHER TIPS

Better use mktime(): mktime(0, 0, 0, $month, 1, $year)

This will generate a timestamp for the 1st day of the given month in the given year with the time 00:00:00.

If you pass "1" as the day, your programming will cause the credit card to expire on the first of the month. This is not the standard practice, which is to have the card expire on the last day of the month. The last of the month can be found with PHP date('t').

Maybe this article will be visible to you (hope so). It teaches most of what you need to know about handling DATETIME values in PHP.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Best regards, ~Ray

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top