Results 1 to 4 of 4

Thread: How to insert GetDate() function in MySQL

  1. #1
    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.

  2. #2
    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);

  3. #3
    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.

  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,541,949.22950 seconds with 16 queries