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