Which php function for inserting users join date?

Hi, just wondering what PHP function is best to use to insert a registering users join date.

something else?

And for my MySQL table, do I use DATE?

This depends on whether or not you want your application to handle the date/time functions or your database.

If you just want to store a DATE (2011-12-25) and not a DATETIME (2011-12-25 00:00:00), the DATE datatype will be fine.

Alright, so if I go with DATE I just use date() and if I go with DATETIME do I use time()?


[fphp]time()[/fphp] provides the current time as a unix timestamp, and [fphp]date[/fphp] formats a timestamp.

The manual should help clear things up.

//Database server time
$sql = 'UPDATE table SET signed_up = NOW();';

//Web server time
$sql = "UPDATE table SET signed_up = '" . date(DATE_ISO8601, time()) . "';";

In this example, the first query sets the signed_up date column to be the current time according to the database server, and the latter, the current time according to the web server.

Any clearer?

Ok, I understand… my only remaining question is if there any benefit to using one over the other? database vs web server time…

the benefit is marginal performance improvement using the builtin database functions, because as far as mysql is concerned, when you pass in some date or number from the outside (e.g. php), it’s got to validate the value first, to make sure it’s okay

also, mysql has time zone support (not sure if php can do this)

Ok thanks r937, appreciate it.

Now to test it out.

Thanks guys!