Transferred from: http://www.cnblogs.com/zhangq723/archive/2011/02/16/1956152.htmlOne, SQL Server date-time functionsDate and time functions in SQL Server1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample:
How SQL SERVER 2000 obtains the current system time with SQL statementsis to use GETDATE ();
getdate in SQL () January 08, 2008 Tuesday 14:59A very powerful date format function in SQL Server
Copy Code code as follows:
Select CONVERT (varchar), GETDATE (), 0);-20
Hh:mi:ss:mmmAM -131* Kuwait Dd/mm/yy Hh:mi:ss:mmmAM About the format conversion of fields in Emaker and the operation code between fields can be added to the attribute "format conversion (read out)" and "format conversion (write)", the "field" position in the table field settings can also be flexible add function. For example: ' AF ' +id or id+ '/' +pwd, convert (varchar (), F1), Convert (int,%)-19110000 (read out) Convert (char (8), convert (int,%)
Use convert in Sql server2000 to get datetime data type style (full)
Date data format processing, two examples:
CONVERT (varchar (16), time one, 20) Result: 2007-02-01 08:02/* time is generally getdate () function or field in Datasheet * *
CONVERT (varchar (10), time one, 23) Result: 2007-02-01/*varchar (10) indicates the format of the date output, if not long
Time comparison in SQL ServerExample:Select COUNT (*) from table where DATEDIFF ([second], ' 2004-09-18 00:00:18 ', ' 2004-09-18 00:00:19 ') > 0Description Select DATEDIFF (Day, time1, time2) corresponds to the following example statementSelect DATEDIFF (Day, ' 2010-07-23 0:41:18 ', ' 2010-07-23 23:41:18 ') time1 > time2 is negative; Time1 time2 are positive; [Day]: will only compare 2010-07-23 ignored 0:41:18 ' Other empathy The following
Tags: date mysq alt class Inter Mon sele create. NetQuery data for 7 days ahead: [HTML]View PlainCopyprint?
SELECT * from data table where Date_sub (Curdate (), INTERVAL 7 day)
[HTML]View PlainCopy print?
Query data for 30 days ahead: [HTML]View PlainCopyprint?
SELECT * from data table where Date_sub (Curdate (), INTERVAL Day)
[HTML]View PlainCopy print?
To query data between a ce
The time format normally deposited in the database is yyyy-mm-ddhh:mm:ss if you want to convert to yyyy-mm-dd Short date format. You can use the CONVERT function. The following is a declaration of the CONVERT function in SQL Server Help:Using CONVERT:CONVERT (data_type[(length)],expression[,style])ParametersExpressionIs any valid microsoft®sql Server™ expression.
In PHP, there are two ways to convert the timestamp of int to datetime, one with the familiar function date ("Y-m-d h:i", Time ()), and the other is to use From_unixtime in SQL (Add_time, "%y-%m-%d %h:%m ") conversion, usually used not much, it is estimated that a lot of people do not know it.
In order to understand the efficiency and difference between them, I made an example. First built a table, only ad
The Mktime function in PHP is queried by time, in fact, in addition to this solution, there are also functions specifically for date and time in MySQL, including date (), Date_add (), Date_sub (), Date_format (), and so on.
The code is as follows
Copy Code
Orders in the last three months, the SQL
CONVERTExplicitly converts a data type expression to another data type. Because some requirements often use different date formats, the following can be found inFormat the date in SQL Server.
SQL Server supports the data format in the Arabic style using the Kuwait algorithm.
In the table, the two columns on the left re
notTRUNCATE TABLE cannot be used for tables that have a FOREIGN key constraint reference.Change-UPDATE statement:Update table name set column name = update value [WHERE condition]WHERE clause does not update all dataFor example, add two points to Zhang San's score in the score table:Update score Table Set score = Score +2 where name = ' Zhang San 'Check select-query statement:1. Select Column name from table name where condition2. SELECT statement Pa
SQL query of date fields
// Query all the data generated at every daySelect * from table where datepart (HH, Date Field) = 8// Query all records whose dates are 2006-7-6Select *From cstrecordWhere (datepart ([Day], optime) = 6) and (datepart ([year], optime) = 2006) and(Datepart ([month], optime) = 7)1) Remove the hour, minute, and secondDeclare @ dateti
--Get current timeSelect getdate ()---Get the current month yy for the year, MM on behalf of the Moon, DD Representative Day, HH representative, the SS on behalf of the second/*
The code is as follows
Copy Code
Year yy 1753--9999 quarter QQ 1--4 month mm 1--12 day of year dy 1--366Day DD 1--31 Week wk 1--53 weekday DW 1--7 (Sunday--saturday)
Hour hh 0--23 minute mi 0--59 second SS 0--59 Milisecond Ms 0--999 * *--datepart is similar to DATENAME implementatio
Definition and usageThe DATEADD () function adds or subtracts a specified time interval from a date.GrammarDATEADD (datepart,number, date) The date parameter is a valid day expression. The number is the number of intervals you want to add, and for the future time, this is positive, and for the past time, this number is negative.The datepart parameter can be the
Take the date in the database, ask you an SQL statement Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061219100404229.html
In the database, there is a table named ABC, with a field attribute of the date and time type. I wrote a statement to find the record of today.
That is to say, select * from ABC where riqi = today
Thank you for your
Add, delete, change, check in SQLFirst, Increase: there are 2 ways1. Insert a single line of data using insert:Syntax: Insert [into] Example: INSERT into Students (name, gender, date of birth) values (' Wang Weihua ', ' Male ', ' 1983/6/15 ') Note: If you save the token name, all columns will be inserted sequentially2. Use the Insert,select statement to add data
In sqlserver2000, convert is used to obtain the processing result of the datetime data type style (full) date data format. Two examples are as follows: CONVERT (varchar (16), time 1, 20: 2007-02-0108:02 * The time is generally the * CONVERT (varchar (10), time 1, 23) Result of the getdate () function or the field * CONVERT (varchar (10) in the data table: 2007-02
In SQL server2000, convert is used to obtain
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.