-2

I know getting a user's registration date should be pretty basic using php, but I was wondering if this was possible directly through mySQL.

I use apache's phpmyadmin and when creating a new column I noticed the type DATE and the default value CURRENT_TIMESTAMP, so I was wondering if it would be possible to add a type of column that automatically set the current date when a new line is created (so when a new user is registered) ?

If this possible and is there any constraints to this ? How can I do this ?

Thanks !

apatik
  • 383
  • 4
  • 17
  • I think it's exactly as you said. `DATE` with `CURRENT_TIMESTAMP` as default. Just may be `DATETIME` is better... – Iurii Tkachenko Dec 25 '15 at 23:22
  • Thanks for answering, indeed some of my questions were answered by chris85's link. However is it possible using only `DATE` since I don't really need the exact time and don't want it to get echo'd later in my user_profile.php ? Currently I'm getting " #1067 - Invalid default value for 'registration_date' " when trying to set the type as `DATE` and the value to `CURRENT_TIMESTAMP`. Anyways thanks the help, I'll keep looking into that – apatik Dec 25 '15 at 23:50
  • 1
    You can save `TIMESTAMP` and later only select the date part: `SELECT DATE(timestamp_column)`. – Paul Spiegel Dec 26 '15 at 00:38

1 Answers1

0

You can set the default value of the date column to NOW()

It will get the current datetime and insert into the date field.

Phiter
  • 14,570
  • 14
  • 50
  • 84