0

Another answer shows how to set a default timestamp. However, it updates only the entry you edit. I was wondering if there is another way that would edit, let's say, the current year in all the entries.

For example, my database has 2 entries that were inserted in the year 2011, so the current date column for the 2 entries would be 2011. I would like to make this column update to 2012 when a new user is inserted, which means now there would be 3 entries and the current year column for all 3 entries would be 2012.

Is this possible?

My main objective is to calculate age.

Community
  • 1
  • 1
Hubert
  • 443
  • 1
  • 8
  • 20
  • If you always want all of the entries to show the current year, why do you need to store them in the DB? Can you let your program get the current year from the system time, and use that? – Adam Liss Mar 30 '12 at 17:54
  • **What** database system, and which version?? **SQL** is just the Structured Query Language - a language used by many database systems - SQL is **NOT** a database product... stuff like this is very often vendor-specific - so we really need to know what database system you're using.... – marc_s Mar 30 '12 at 17:58
  • @marc_s Hi...i am using xxamp phpmyadmin...not sure if that is what i am suppose to give... – Hubert Mar 30 '12 at 19:23
  • @Hubert: DBMS stands for DataBase Management System. You are using MySQL (based on your comment and your linked question). – ypercubeᵀᴹ Mar 30 '12 at 19:47
  • I wonder will this code `SELECT convert(datetime, '10/23/2016', 101) -- mm/dd/yyyy` help me to convert the string input into text fields to Date format? – Hubert Mar 30 '12 at 20:35

2 Answers2

2

You really don't need to - and should NOT - store the current year in a table's column (and possibly in several million rows) - unless you are writing a Star Trek application where some characters live in 2012 and others in 42012 (in other words if the "current year" is not the same for all).

You can always use this in your computations:

YEAR( CURRENT_DATE() )
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
0

If you store the user's birthdate as a DATE column then you can calculate their age. These calculations range from the "good 99%' of the time, to the good for everyone including leap year babies

gview
  • 14,876
  • 3
  • 46
  • 51
  • hi...thanks for help...i like to know because if u set date to be the format...the figure must be yyyy-mm-dd... is there anyway i can make it like dd/mm/yyyy? – Hubert Mar 30 '12 at 17:58
  • Date, Datetime, and timestamp are all stored internally as integers, and you can use mysql functions to format them virtually in anyway you want in your SELECT using DATE_FORMAT(date, 'format string') – gview Mar 30 '12 at 18:05
  • if i have this line `$adddob = $_POST['dob'];` how do i apply Date Format?? Sorry i am not very good in this...Thanks in advance – Hubert Mar 30 '12 at 19:21