Current location: Hot Scripts Forums » Other Discussions » Database » Default value for the Datetime data type...

Default value for the Datetime data type...

Reply
  #1 (permalink)  
Old
Clark_Kent's Avatar
Newbie Coder
 
Join Date: Mar 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Question Default value for the Datetime data type...

Hey Everyone,

I have a datetime data type in one of my tables and i want it to set the current date to itself when a record is inserted into the table. I know i could use the timestamp data type and assign CURRENT_TIMESTAMP as the default, but can this be done with the datetime data type as well?

I already have a field with the timestamp data type, it is used to determine when the record was last updated. I want another record to do basically the same thing except it must only contain when the record was added to the database. I tried using timestamp with its default value but apparantly i can't do that, navicat won't let me assign more than one timestamp field a default value of CURRENT_TIMESTAMP... so i'm turning towards using the datetime data type to get this done, is there a default value i could use to allow the datetime data type to assign the current date and time to itself when a record is added to the table?

Thanks for your help ,

- CK

BTW: I'm using MySQL
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Clark_Kent's Avatar
Newbie Coder
 
Join Date: Mar 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

Hey Everyone,

I solved the problemmo, got a bit ahead of myself posting first... Instead of specifying a default value i had a MySQL function execute to add the current date when a record is added to a table in the database. Using the datetime data type i used the CURDATE() function to assign the current date to its corresponding field. I'll clarify further by providing an example...

INSERT INTO your_database_name (current_date, ...) VALUES (CURDATE(), ...)

The output of the CURDATE() function is '2003-12-31 01:02:03', i then applied a mask so it displays friendlier output to the user.

Hope this helps someone ,

Regards,

- CK
Reply With Quote
  #3 (permalink)  
Old
Clark_Kent's Avatar
Newbie Coder
 
Join Date: Mar 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
I unfortunately rushed through my previous post ... have a few typos...

INSERT INTO your_database_name ...

your_database_name is supposed to be your_table_name.

The output of the CURDATE() function is '2003-12-31 00:00:00' - it returns zeros where the time is supposed to be, doesn't return the actual time.

Sorry about the typos,

- CK
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Left Join with Where & Count is eluding me CutAndPaste PHP 8 12-13-05 04:46 AM
need some help with this code buzzby PHP 0 06-20-04 04:07 AM
Newbie MySQL fccolon PHP 2 03-16-04 11:54 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 08:33 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.