Data cleansing Note: correct English date conversion reports "invalid month", note English
Original Works are from the blog of "Deep Blue blog". You are welcome to repost them. You must specify the source when you repost them. Otherwise, you have the right to pursue legal liability for copyright.
Deep Blue blog: http://blog.csdn.net/huangyanlong/article/details/46340291
Background]
Data in the format of "9
:yyyymmddhhmmssffff}", DT);Calculates the difference in the number of days between 2 dates-----------------------------------------------DateTime dt1 = Convert.datetime ("2007-8-1");DateTime DT2 = Convert.datetime ("2007-8-15");TimeSpan span = dt2. Subtract (DT1);int Daydiff = span. Days + 1;Calculate the number of days of the month in a year-----------------------------------------------int days = Datetime.daysinmonth (2007, 8);days = 31;Add one day
To create a test table:CREATE OR REPLACE VIEW v asselect to_date (' 2015-1-1 13:14:15 ', ' yyyy-mm-dd HH24:MI:SS ') as C from DUAL; SELECT * from V;Two date subtraction, get the number of days, multiplied by 24 is the hour, and so on, you can calculate the second, if you want to calculate the month interval, you need to use the function Months_between.The SQL cod
Date interval: year, month, day, hour, minute, second, interval: Year
Create a test table:
Create or replace view v ASSELECT TO_DATE ('1970-1-1 13:14:15 ', 'yyyy-MM-DD HH24: MI: ss') AS c from dual; SELECT * FROM v;
Subtract two dates to get the number of days, multiply by 24 to the hour, and so on. you can calculate the second. to calculate the month interv
If you have a demand, check the past 12 months of the tax trend chart, do not recommend you in the SQL Mosaic returned 12 months of data, it is likely to lead to slow SQL, it is recommended in the Java code to get the date, and then passed into the SQL based on the date to q
In the recent project development process, encountered SQL Server automatically split the monthly function requirements, here online collation of information.
1, why the need for custom split month
Today, when you comb through all the functions of a platform, you find a custom split-month function, which is to specify the d
Tags: des style blog http color using OS strongSELECT * FROM table WHERE convert (Nvarchar, DateAndTime, 111) = CONVERT (Nvarchar, GETDATE (), 111) ORDER by DateAndTime DESCRecord of the Month
SELECT * FROM table WHERE DateDiff (Month,[dateadd],getdate ()) =0
Week record
SELECT * FROM table WHERE DateDiff (Week,[dateadd],getdate ()) =0
Day recordSELECT *
This week: SELECT * FROM table where DATEDIFF (Week,c_calltime,getdate ()) =0--c_calltime as Date fieldThis month: SELECT * FROM table where DATEDIFF (Month,c_calltime,getdate ()) =0--c_calltime as Date fieldThis season: SELECT * from table where DATEDIFF (Qq,c_calltime,getdate ()) =0First half year 1-6, after half yea
Tags: access mil csdn second part details datetime log ArchSQL Query day, week, month record--Day of enquiry:[SQL] View plaincopyprint?SELECT * FROM info where DateDiff (dd,datetime,getdate ()) =0--Query within 24 hours:[SQL] View plaincopyprint?SELECT * FROM info where DateDiff (hh,datetime,getdate ()) --info is the table name, DateTime is the field value in the
(
TO_CHAR (SYSDATE,
‘Day, DDth Month YYYY‘,
‘NLS_DATE_LANGUAGE=Spanish‘));
END;
/
Domingo , 07TH Agosto 2011 In addition, I can use the FM element modifier in order to remove extra 0 and spaces from the display results. BEGIN
DBMS_OUTPUT.put_line (
TO_CHAR (SYSDATE,
‘FMDay, DDth Month YYYY‘));
END;
/
Sunday, 7TH August 2011 You can also use the format mask to
Label:Processing of date and time data.(1) String date ' 20080301 ', which is a string date, but must be guaranteed as a four-bit year, two-bit month, and two-bit date. For example, the Query order table date is greater than ' 200
other examples in this article will only use the datediff and dateadd functions to calculate the date we want. In each example, the date to be calculated is obtained through calculation but the previous time interval, and then addition or subtraction is performed.
This is the SQL script used to calculate the first day of a
Label:That day: SELECT * from T_news where DateDiff (Day,addtime,getdate ()) =0 Last three days: SELECT * from T_news where DateDiff (Day,addtime,getdate ()) Week: SELECT * from T_news WHERE (DATEPART (wk, addtime) = DATEPART (wk, GETDATE ())) and (DATEPART (yy, addtime) = DATEPART (yy, GET DATE ())) Note: You cannot use the DateDiff difference at this time as 7, because DateDiff only represents the number of intervals
Common SQL Server date comparison and date query statements
In SQL Server, you may need to obtain the current date and calculate some other dates. For example, your program may need to determine the first or last day of a month. M
that the time in SQL Server is exactly 3 milliseconds. That's why I need to subtract 3 milliseconds to get the date and time I want.SELECT DateAdd (Ms,-3,dateadd (mm, DATEDIFF (Mm,0,getdate ()), 0))The time portion of the calculated date contains the time at which SQL Server can record the last moment of the day ("23:
', ' 2005-7-25 22:56:32 ') returns a value of 514,592 secondsDateDiff (' d ', ' 2005-07-20 ', ' 2005-7-25 22:56:32 ') returns a value of 5 days3.DatePart (' W ', ' 2005-7-25 22:56:32 ') returns a value of 2 that is Monday (Sunday is 1, Saturday is 7)DatePart (' d ', ' 2005-7-25 22:56:32 ') returns a value of 25, or 25thDatePart (' y ', ' 2005-7-25 22:56:32 ') returns a value of 206 that is the No. 206 Day of the YearDatePart (' yyyy ', ' 2005-7-25 22:56:32 ') returns a value of 2005 that is 200
DateDiff (DD, GetDate (), datetimcol) = 1 last seven days select * from TableName W Here DateDiff (DD, Datetimcol, GetDate ()) SQL Date function1. Current system date, timeSelect GETDATE () 2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample: Add 2 days to the dateSelect DATEADD (day,2, ' 2004-10-15′) – return: 2
SQL Month Rollup query statement
Select ' Pencil ' as [month],SUM (case month (date) When 1 then pencil else 0 end) as [January],SUM (case month (date) when 2 then pencil else 0 end) a
Jsp adds a date to the database
MS SQL SERVER:
NSERT into student (studentid, time1) values ('15', getdate ());
MY SQL
Insert into tablename (fieldname) values (now ())
Obtains the number of all rows of a table in the database.
Connection conn = DbConnection. connectToDb ();
Statement stat = conn. createStatement ();
ResultSet rs1_stat.exe cuteQuery ("select coun
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