Tag: datetime

SQL query error :Incorrect Syntax Near “#”?

When I try to execute this SQL query: savInto.CommandText = “update onCommands set warnDate =#” & movDate.Value.ToString(“MM/dd/yyyy”) & “#,updateDate =#” & Date.Now.ToShortDateString & “#,transportCompany ='” & Trim(Company.Text) & “‘ where ID =” & moveID I get this error: Incorrect syntax near ‘#’

Subtract fetched datetime from current date time

I need to calculate the time difference between the localDatetime and a Datetime fetched from a specific row in my database-table(csv) called ReportedDateAndTime. I searched a lots of solutions but it doesn’t working for me. Displaying localtime & the fetched time from Database are working. But the time difference doesn’t. Here is my code so […]

c# SQL Server : DATETIME datatype

I am writing a unit test which stores an object with a DateTime parameter into a DATETIME2 SQL Server database column. I then create a temporary DateTime object called new_date_time and set that value to DateTime.Now. The new_date_time value is then used to update the previous value and the SQL query to do this completes […]

How to convert Date-time values in SAS into TSQL

I am reading some date-time values from SAS server and the way SAS date values are stored is in numeric variables. Date values represent the number of days since January 1, 1960. Time values represent the number of seconds since midnight. Datetime values represent the number of seconds since January 1, 1960. I am able […]

how to get 30 days from Todays

Select from x WHERE yid = rid AND (h.test1 <=todaysdate) AND (h.test1>= 30 days from today) How can I write that line 30 days from today in a query? Instead I put a date or a month from todays date.

Date and Time Formatting in VB.net and SQL Server

I have a table in which data is been logged in ‘yy/MM/dd HH:mm:ss’ format and my regional setting is ‘2016-04-02 14:25:15’ type. I want to get details in a following query but it is not populating any results The query I used is select Date_time, alarm_id, alarm_message from table01 where Date_time between ‘” & DateTimePicker5.Value […]

Convert integer value to DateTime in SQL Server 2012

I have a table called “EventLog” which has the column called nDateTime of type int. This is the table “EventLog” with some values: —————– | nDateTime | —————– | 978307200 | —————– | 978307219 | —————– | 978513562 | —————– | 978516233 | —————– | 978544196 | —————– | 1450379547 | —————– | 1472299563 | […]

GET UTC Date of a past date

My database have date values saved in GMT time zone in int format. I am trying to convert the date to local timezone, but the issue arises when the date is a past date, For instance in my case offset for date Dec 1, 2012 will be -5 and for June 15, 2010 will be […]

SQL: Error when converting varchar to datetime

WITH Valid_dates (ValidDate) AS ( SELECT ’19’ + SUBSTRING(column, 0, 3) + ‘-‘ + SUBSTRING(column, 3, 2) + ‘-‘ + SUBSTRING(column, 5, 2) AS ValidDate FROM table WHERE SUBSTRING(column, 3, 2) <= ’12’ –Max month AND SUBSTRING(column, 3, 2) >= ’01’ –Min month AND ISNULL(SUBSTRING(column, 3, 2), ”) <> ” –Empty string AND SUBSTRING(column, 5, […]

Convert Date Stored as NUMERIC to DATETIME

I am currently working on a query that needs to calculate the difference in days between two different dates. I’ve had issues with our DATE columns before, because they are all being stored as numeric columns which is a complete pain. I tried using CONVERT as I had done in the past to try and […]

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