Tag: datetime

SSIS Error importing Excel Date (truncation error)

I am sorry to post what seems a very simple issue but I cannot find an answer and I am wasting days (not just hours at this point). I am fairly new to SSIS and it is just kicking my backside. Background: Pretty straightforward SSIS Package to import an Excel sheet into a Staging table […]

Rounding Datetime to nearest 15 minutes in SQL Server

I have a problem in SQL Server with rounding datetime. I got datetime in column rec_datetime, but I want to round this datetime in a new column r_datetime, which has to be rounded to nearest 15 min, for the whole column rec_datetime. Example: [2015-11-24 19:06:00.000] – expected result -> [2015-11-24 19:00:00.000] [2015-11-24 19:09:00.000] – expected […]

How to compare a datetime type in SQL Server

So I have a column in my DB on SQL Server that is a datetime. I want to do this simple select statement: SELECT * FROM Res Where dateSubmit=’6/17/2010 5:01:26 PM’ dateSubmit is a datetime data type and my database has a row where dateSubmit is 6/17/2010 5:01:26 PM However, when I execute this statement […]

Getting the hour from a datetime?

How can I select the hour from a datetime? I’m looking for the equivalent of Oracle’s TO_CHAR( d, ‘HH24′ ), which would return 17 for 2010-06-23 17:22:31. I tried to find out about the best time (best answer/question-ration) to ask an SQL-related question on StackOverflow, using Data Explorer. I got it to work, but I’m […]

how to get current month name, start date and end date between two dates in sql server

create procedure dummy2 as begin declare @sDate datetime, @eDate datetime select @sDate = ‘2013-02-25’, @eDate = ‘2013-03-25′ ;with cte as ( select convert(datetime,left(convert(varchar,@sdate,112),6) + ’01’) startDate , month(@sdate) n union all select dateadd(month,n,convert(datetime,convert(varchar,year(@sdate)) + ‘0101’)) startDate, (n+1) n from cte where n < month(@sdate) + datediff(month,@sdate,@edate) ) select CONVERT(varchar(20), DATENAME(MONTH, startdate))as Months, startdate, dateadd(day,-1,dateadd(month,1,startdate)) enddate […]

Truncate seconds and milliseconds in SQL

I’m having a bit of trouble with truncating data. I’m using SQL’s GETDATE() function to get the current date and time and enter them into a database. However, I only want to save the date and time up until the minute. In other words, I want dd/mm/yyyy hh:mm:00.000 or dd/mm/yyyy hh:mm to be saved when […]

How is timezone handled in the lifecycle of an ADO.NET + SQL Server DateTime column?

Using SQL Server 2008. This is a really junior question and I could really use some elaborate information, but the information on Google seems to dance around the topic quite a bit and it would be nice if there was some detailed elaboration on how this works… Let’s say I have a datetime column and […]

How to get SQL Server DateTime field in ODBC native client

I’m have SQL Server table: CREATE TABLE [dbo].[Table1]( [rec_id] [int] IDENTITY(1,1) NOT NULL, [id] [int] NOT NULL, [date] [datetime] NOT NULL, [ps] [varchar](200) NULL ) ON [PRIMARY] I’m getting data by a code: status = SQLExecDirect(statement, (SQLWCHAR*)TEXT(“SELECT * FROM [DBNAME].[dbo].[Table1]”), SQL_NTS); cout << “SQLExecDirect returned ” << status << “\r\n”; if (status == SQL_SUCCESS_WITH_INFO || […]

Howto convert datetime to date with an ODBC function?

Question: I need to get the DATE ONLY (= date WITHOUT time) with an ODBC escape sequence. However SELECT {fn CONVERT(SomeTable.Col_With_DateTime_Value, SQL_DATE)} FROM SomeTable does return the column as datetime value (date WITH time). Is there any ODBC function I can use to get the date value only ? Note: This is not a duplicate […]

Updating year in datetime variable

I’m playing around with manipulating a datetime variable. I can’t seem to find a way to update a datetime variable year to the current year. For example I have 2007-12-01 00:00:00.000 But I would like that to be 2012-12-01 00:00:00.000 (The current year were in) I’ve been playing with datediff, but I can’t seem to […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.