LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2008, 02:25 AM   #1
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
How do I INSERT the current date into a table in MYSQL?


How do I do this please?

Thanks.
 
Old 11-28-2008, 02:29 AM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
http://letmegooglethatforyou.com/?q=...n+MYSQL%3F+%20 - really easy to find with a search engine. The 3rd result down may be useful.
 
Old 11-28-2008, 02:32 AM   #3
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Stroll over to mysql.com, select the manual for your version of MySQL and read chapter "11.6. Date and Time Functions".
 
Old 12-12-2008, 02:27 AM   #4
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
Just to add, is this alright?:
(I want the date in this format: 13th December, 2008)


$sth=$dbh->prepare (qq{ INSERT INTO reviews VALUES ('"$ary[0]"','"$parameter[0]"','"$parameter[1]"','"$parameter[2]"',DATE_FORMAT(CURDATE(),"%M, %e, %Y") ;
 
Old 12-14-2008, 01:39 AM   #5
arunmathew1984
Member
 
Registered: Nov 2008
Posts: 31

Rep: Reputation: 15
mySQL supports the function now() which can be used to get the current date and time.

Linux Archive

Last edited by arunmathew1984; 12-20-2008 at 11:24 AM.
 
Old 12-14-2008, 01:39 AM   #6
arunmathew1984
Member
 
Registered: Nov 2008
Posts: 31

Rep: Reputation: 15
You might find this link useful as well - http://dev.mysql.com/doc/mysql/en/da...functions.html
 
Old 12-14-2008, 05:35 PM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Normally it is best to store dates in their "natural" format, (then sorting will work properly, and they consume less space) When you need to retrieve the date you can then format it as you require.
 
Old 12-15-2008, 01:08 AM   #8
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
but is my actual code alright? (all the DATE_FORMAT(CURDATE() stuff)?
 
Old 12-15-2008, 01:17 AM   #9
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You can quickly test it by doing:

select (DATE_FORMAT(CURDATE(),"%M, %e, %Y"))

you'll then find that you get "December, 15, 2008" Trying:

select (DATE_FORMAT(CURDATE(),"%D %M, %Y"))

will give you "15th December, 2008"
 
Old 12-15-2008, 01:39 AM   #10
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
thx a lot, graemef
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto insert a pdf document into a mysql table jadewarrior Linux - Server 4 02-23-2007 05:18 AM
current date - yesterday's date newbie_adm Linux - Newbie 4 09-04-2006 03:56 PM
Can not insert word file into mysql table (in blob field) prabhatsoni Linux - Software 2 07-21-2006 05:01 AM
Mysql - Howto insert 'admin' account into table ??? b:z Linux - General 6 03-29-2005 03:44 AM
Changing date format in MySQL table vous Linux - Software 8 09-03-2003 06:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration