Operation of time dates in SQLServer

xiaoxiao2021-03-06  14

First, there is a field of a DateTime type in the database.

Then, if you want to take the current time with the following functions java.util.date Date = new java.util.date (); // Take the current time SimpleDateFormat sf = new java.text.SIMPLEDATEFORMAT ("YYYY / MM / DD") ; // Conversion time format string formatedate = sf.format (date); // conversion time function

Then deposit into the database, in the database, the database will transform the time to YYYY-MM-DD this format

About Query Data First: Querying the data for a certain month first gives a month: int month = 3 and then select * from [table] where month ([datetime]) and year ([datetime]) where Month () is SQL's function is used to obtain the month in the DateTime field, and Year () is the year function.

Second: Query a date interval data Select * from [Table] where Date Between 'Givendate1' and 'givendate2' where givendate1 can give YYYYMMDD to YYYY-MM-DD for YYYY-mm-DD for the date format for given the query. If you need to include a single quotes, if you can use Between to include the first one and the second, you can use> or you check this time does not include this give date.

转载请注明原文地址:https://www.9cbs.com/read-50086.html

New Post(0)