Tag: datetime

How to get Saturday's Date (Or any other weekday's Date)- SQL Server

How to get Saturday’s Date. I have today’s date with me. GETDATE() How to do this. For eg. TODAY is 08-08-2011 I want output as 08-13-2011

Why are null values fetched from ADO Recordset instead of correct ones depending on the order of retrieval? (The DB table has NTEXT values)

I have a DB table with two datetime nullable columns that I need to read from an ASP page using VBScript. This is the code I wrote: Set cmd = Server.CreateObject(“ADODB.Command”) With cmd .ActiveConnection = conn .CommandType = adCmdText .Prepared = True .CommandText = “SELECT * FROM storico_corsi WHERE stc_id = 5 ” Set rs […]

why ss round to nearest minute that will change day

I am using sql server 2008 R2 and due to one problem i am able to know that smalldatetime round ss to nearest minute . here is content from MSDN . ss is two digits, ranging from 00 to 59, that represent the second. Values that are 29.998 seconds or less are rounded down to […]

DateTime query on only year in SQL Server

I want to select multiple records on the basis of a matching year, for example in table tab where columns are [id] int, [name] varchar, [bookyear] datetime I want to select all records where the year is 2009. The following query gives 0 results: SELECT [ACCNO] ,[Roll No] ,[IssueDate] ,[DueDate] FROM [test1].[dbo].[IssueHis$] where [IssueDate] between […]

Set time part of datetime variable to 18:00

I need to set datetime variable to two days from now but it’s time part must be 18:00. For example if i call getdate() now i’ll get 2010-05-17 13:18:07.260. I need to set it to 2010-05-19 18:00:00.000. Does anybody have a good snippet for that or any ideas how to do it right?

NHibernate won't persist DateTime SqlDateTime overflow

I am working on an ASP.NET MVC project with NHibernate as the backend and am having some trouble getting some dates to write back to my SQL Server database tables. These date fields are NOT nullable, so the many answers here about how to setup nullable datetimes have not helped. Basically when I try to […]

How can I convert a OLE Automation Date value to a date in SQL Server

My application stores dates as OLE Automation doubles with the DateTime.ToOADate() command. Now, I need to create a SQL view wich shows me the Date stored. How can I quickly convert the double to a date? Thanks

Does SYSDATETIME() cost more than GETDATE()?

Is there any reason why I should stop using SYSDATETIME() everytime, instead of GETDATE() ? Don’t they both ask the cpu what time it is or does sysdatetime need more instructions to calculate the fractions? Does Getdate work on rounding it? Can sysdatetime be faster because it’s not working on rounding? I obviously wouldn’t use […]

SQL datetime format to date only

I am trying to select the DeliveryDate from sql database as just date. In the database, i am saving it as datetime format. How is it possible to get just date?? SELECT Subject, DeliveryDate from Email_Administration where MerchantId =@ MerchantID 03/06/2011 12:00:00 Am just be selected as 03/06/2011.. Thanks alot in advance! 🙂

SQL Server: Convert Between UTC and Local Time Precisely

I have a few columns in an SQL server 2008 R2 database that i need to convert from local time (the time zone the sql server is in) to UTC. I have seen quite a few similar questions on StackOverflow, but the answers all fail to work correctly with daylight saving time, they only take […]

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