Tag: datetime

SQL Server date format handling

I am running the SAME Delphi 2007 code on two different Windows 7 machines and accessing the SAME SQL server database on a remote server. On one machine a date in the database is read in the format 2013-01-25 00:00:00.000 which causes the application to crash when it tries to convert this date to a […]

Sql server not Accepting Date from text box

I am not able to insert date from text box which is in DD/MM/YYYY format. I am using Visual Studio 2008 on Windows 7. my language and regional settings are “ENGLISH(United Kingdom)”, and my system is showing today’s date like 12/12/2013. The same date i have get in text box via form On load event. […]

Set 24 hours TimeInterval in Where Clause of SQL server

I need to query a table in an sql server, in which the Query results to be filtered between yesterday’s 5:00Pm to Today’s 5:00PM. But the Table contains Date and Time in seperate fields. Any help would be appreciated. Thanks

How to Combine a query with a AVG query when using datetime SQL 2008 R2

I am trying to combine two query’s together but I’m having trouble as it is a datetime column. right now I have a query that finds all the users + there slowest and fastest “Segment” time but I also need to find the avg segment time below are the two query’s I am using right […]

Convert nvarchar(50) to datetime (Second's part not coming after update the table)

i would also like to convert my nvarchar(50) timecode to datetime type. My code is this one: (example time 27.03.2013 17:11:27) UPDATE test set mytime = CONVERT(nvarchar(50), convert(datetime, mytime, 104)) alter table test alter column mytime datetime Result: 2013-03-27 17:11:00.000 i always get the result without seconds! All seconds are reseted to zero. i want […]

how to check difference in time

following code returns CREATE TABLE #emp1 ( empid VARCHAR(50), empname VARCHAR(50), intime SMALLDATETIME, outtime SMALLDATETIME ) INSERT INTO #emp1 VALUES (2500, ‘Arun’, ‘2014-01-01 09:00:00’, ‘2014-01-01 10:30:0’), (2500, ‘Arun’, ‘2014-01-01 11:00:00:00’, ‘2014-01-01 11:00:0’), (2500, ‘Arun’, ‘2014-01-01 11:30:00:00’, ‘2014-01-01 19:00:00’) SELECT empid, Cast(intime AS DATE) AS workingday, empname, RIGHT(‘0’ + CONVERT(VARCHAR, Floor(Sum( Datediff( mi, intime, outtime)/ 60.0))), […]

Sorting Date Difference in SQL

I am writing: Select datediff(hh,getutcdate(), End_Date) as “Duration” from MasterTable order by Duration To get difference of hour values in ascending order. I get output, Duration ——– -259 -210 5 10 22 35 75 105 235 But I want, ordering has to be done based on positive numbers and negative numbers of hour values. So, […]

Finding MIN nvarchar related to datetime

I have a table that contains a list of patient services and when they arrived to that service. I want to be able to pull just the first service after the emergency department. Here is the table: Service DateTimeIn H EMERGENCY MEDICINE 2013-01-01 10:43:00.000 H MEDICINE E 2013-01-06 23:43:00.000 H MEDICINE E 2013-01-07 17:18:00.000 H […]

SQL Server: explanation needed to understand combination of DATEADD and DATEDIFF

I am pretty new to SQL and use the following lines within a Select in order to get the first and last Monday of October (@selYear defines the year). Can someone here tell me how to adjust this so that it returns the second, third and fourth Monday of October + provide me an explanation […]

odbc_prepare for procedure with datetime input parameters

Somewhat new to odbc_prepare statements and am having an issue when trying to execute a stored procedure that requires datetime input parameters. If I am to execute using odbc without using the prepared statement as displayed below I have no issue… $dblink = db_connect(); $query = “EXEC dbo.[ProcedureName] ‘” . $dateinput . “‘”; odbc_exec($dblink, $query); […]

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