How does MySQL Database Obtain the current date? JSP, MySQL

Source: Internet
Author: User
My website uses MySQL and one field is "date". When I add a record MySQLSet the "date" Default Value of the record to the current date,
I tried timestamp, but the default value is 14 bits, that is, there are years, months, days, hours, and minutes. What should I do if I only want years, months, and days?
Bytes ------------------------------------------------------------------------------------
Trash. Truncated to year, month, and day
Bytes -------------------------------------------------------------------------------------- Date type

Select curdate ()
Bytes -------------------------------------------------------------------------------------- I directlyMySQLInsert record in CC, no needMySQLCommand, I want to insert each record, the record date is the current date, can you do it with curdate? Curdate () inMySQLHow to use it in CC?
Bytes -------------------------------------------------------------------------------------- It's so simple
Intercept

Bytes -------------------------------------------------------------------------------------- MySQL> Select now ();
MySQL> Select sysdate ();
MySQL> Select curdate ();
MySQL> Select current_date;
MySQL> Select curtime ();
MySQL> Select current_time;

Try and choose one you need
Bytes -------------------------------------------------------------------------------------- Kevinliuu (@. @)
I want to setMySQLThe default value is the current date, andMySQLCC
Bytes -------------------------------------------------------------------------------------- MySQLCC never used

No matter what, aren't you using SQL statements to insert data? If yes, it can be solved.

Insert into talbe (ddate) values (select now ());
Bytes -------------------------------------------------------------------------------------- Select date (date1) from test
Bytes -------------------------------------------------------------------------------------- If the SQL statement is used, I will,
I am usingMySQLCC graphic interface, just like in access, right-click or insert a record. The problem isMySQLEach field has a default value of 0000-00-00. I want this default value to be the current date.
Bytes -------------------------------------------------------------------------------------- Impossible
Bytes -------------------------------------------------------------------------------------- But Timestamp can do it.
However, the timestamp has a time, minute, and second, and I don't know how to intercept it into a date, year, month, or day.
Bytes -------------------------------------------------------------------------------------- You want to use default when creating a table!
Bytes -------------------------------------------------------------------------------------- To chouy (chouy)

Yes. Is there a way?
Bytes -------------------------------------------------------------------------------------- The default clause specifies a default value for a column. with one exception, the default value must be a constant; it cannot be a function or an expression. this means, for example, that you cannot set the default for a date column to be the value of a function such as now () or current_date. the exception is that you can specify current_timestamp as the default for a timestamp column. see section 11.3.1.1, "timestamp properties as of MySQL 4.1 ".

If a column definition between des no explicit default value, MySQL determines the default value as described in section 11.1.4, "Data Type default values ".

Blob and text Columns cannot be assigned a default value.

The above is copied from the official MySQL website! It must be useful!
Bytes -------------------------------------------------------------------------------------- O yeah
Bytes -------------------------------------------------------------------------------------- To chouy (chouy)
I do not know English. Can I speak Chinese?
Bytes -------------------------------------------------------------------------------------- The above general meaning is:

The value specified in the defalut clause must be a constant and cannot be a function. However, the default value of Timestamp can be set to current_timestamp.

I think your date type cannot specify the default value you need.
I have to use the function in insert into. I think this should not be too costly in programming.
Bytes -------------------------------------------------------------------------------------- That is to say, all functions except Timestamp can be used as the default value for database insertion.
Bytes -------------------------------------------------------------------------------------- Back to kevinliuu (@. @) () Reputation: 107
-------------------------------------
Only when the column data type is Timestamp can the default value be specified as current_timestamp.
For example:
Create Table 'event '(
'Something' char (20 ),
'Time' timestamp default current_timestamp
)

This statement can be used when inserting a piece of data:
Insert into event (something) values ('thing1 ');

Insert result:
+ ----------- + --------------------- +
| Something | time |
+ ----------- + --------------------- +
| Thing1 | 15:32:40 |
+ ----------- + --------------------- +
Bytes -------------------------------------------------------------------------------------- You only need to convert the time.

Select something, date (time) from event
Bytes -------------------------------------------------------------------------------------- To chouy (chouy)
In this case, the timestamp field can only be intercepted,MySQLThe default value is timestamp (14). But how can we extract the first 8 digits?
FromMySQLNo timestamp (8) Since 4.0
Bytes -------------------------------------------------------------------------------------- To dreamover)

You only need to convert the time.

Select something, date (time) from event

In JSP, when I write select Field 1,... Field 2, date (time) from table 1, an error occurs. My Date Field name is "date"

Bytes -------------------------------------------------------------------------------------- Try it

Select date ('date') from Table1

'Is the input symbol of the key under ESC

It is best not to use keywords for field names, such as date, Char, and Int.
Bytes -------------------------------------------------------------------------------------- To dreamover)
Still not ..
The field name has also been changed.
Bytes -------------------------------------------------------------------------------------- You usedMySQLWhat is the version number?

Maybe there is no date function in it. Let's take a look at the help and find out which date functions are available in your version, and there are many functions that can be used for the purpose.
Bytes --------------------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.