views:

134

answers:

2

Hi there,

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

+1  A: 

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
Rich Adams
+1  A: 

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.

ThiefMaster