Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-05-2009
Member
 
Join Date: Apr 2009
Posts: 107
How to insert GetDate() function in MySQL

I am developing an application in which i wanted to insert date into mysql table field, I know that there is some command in MS SQL that may used as the default value for the fields (DateTime datatype) will generate date & time value when a new row is inserted.

I wanted to apply this in my application but have no idea how to implement that if someone aware of this please let me know.
Reply With Quote
  #2  
Old 18-05-2009
Member
 
Join Date: Oct 2008
Posts: 167
Re: How to insert GetDate() function in MySQL

If you wanted to insert GetDate() function you could also achieve through the Unix timestamp where number of seconds elapsed asked from the specific time period. You could extract the date out of it with the MySQL function FROM_UNIXTIME:

SELECT FROM_UNIXTIME(1268314571);

or you could convert it to a unix timestamp form with UNIX_TIMESTAMP

SELECT UNIX_TIMESTAMP('2008-12-24 10:33:45);
Reply With Quote
  #3  
Old 18-05-2009
Member
 
Join Date: Jan 2006
Posts: 211
Re: How to insert GetDate() function in MySQL

From the following link you could use any method like
Code:
SEC_TO_TIME(),STR_TO_DATE(),CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP
The Functions that expect date values usually accept datetime values and ignore the time part. Functions that expect time values usually accept datetime values and ignore the date part.

Code:
mysql> SELECT something FROM tbl_name
    -> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;
Or you may use the above Functions that return the current date or time each are evaluated only once per query at the start of query execution. This means that multiple references to a function such as NOW() within a single query always produce the same result.
Reply With Quote
  #4  
Old 18-05-2009
Member
 
Join Date: Jan 2009
Posts: 140
Re: How to insert GetDate() function in MySQL

In the above post have already suggested you to switch over from datetime to use the timestamp. It is always recommended to use timestamps as you can deal with any time differences and format the date/time how you want when displaying.Or you may also try using $thetime = time(); and then putting $thetime into the field that stores the purchase date. time() function also returns a unix timestamp for the current time and you can then format it as you wish when you recall it.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to insert GetDate() function in MySQL"
Thread Thread Starter Forum Replies Last Post
Insert data from an Excel file into MySQL. Antonio1 Windows Software 3 24-11-2009 01:51 AM
How to Insert data into MySQL table Mahendra varma Software Development 4 04-10-2009 04:42 AM
Insert Images in MySQL from FTP MeteoWatch Software Development 2 02-07-2009 01:06 AM
Batch insert on MySQL is possible Shreevats Software Development 3 16-05-2009 06:13 PM
how to insert a image in mysql cnu0870 Software Development 5 28-04-2009 05:15 PM


All times are GMT +5.5. The time now is 03:11 AM.