I have a date field in an SQL database. I would like to automatically add the date when a record is created. Is it best to add the date using PHP or is there a way to automatically add the date in the SQL database when the record is created?

    yes there is a way to automatically update the date

    while creating the table use default sysdate or current_Timestamp

    try one of these depending on which database you are using for oracle sysdate workds and for mysql current_timestamp

    it will definately work

    aman

      Thanks Aman,
      I am using MySQL so I just created a field called "date TIMESTAMP". The only problem is that now when I do a query through PHP I get the date like this:

      20020911120637

      I would like to get it as mm-dd-yyyy. Is there a way of doing this through PHP? or is there another field type in MySQL that will give me this format?

      Also, is a TIMESTAMP field updated every single time I make a change to that record or just when it's initially created? Is there a way to create a field that's only updated when the record is first created?

      I know this is a lot but I am not a programmer and I am completely lost when it comes to this. THanks...

        Write a Reply...