Tag: datetime

Seeding my DB with Entity Framework DateTimes

I am using Code First Workflow with Entity Framework 6.1.3 and I am trying to seed my database with some data by adding a migration like so: public partial class SeedDatabaseWithBusinesses : DbMigration { public override void Up() { Sql(“INSERT INTO Businesses (GooglePlaceId, Name, CurrentMenu, LastUpdated)” + ” VALUES (‘googlePlaceIdHere’, ‘Examples Businesses Name’, ‘Fish and […]

How can I convert a JSON date with timezone to a SQL Server datetime?

I saved the output of a JSON object in a CSV file. I want to import the data into SQL Server. I have tried to cast the JSON date column to a SQL Server datetime data type. select cast(‘2009-06-18T16:44:20+0000’ as datetime) This causes an error to be raised: Conversion failed when converting date and/or time […]

SQL Server stored procedure passing datepart year as a parameter

I was wondering if anyone could help please, I’ve got the below procedure, I’m trying to enable it so that an end user can pass the year portion of the date only and it will query based on that parameter so at the moment I’m querying between ContractDate.ContractDate >= 01/01/2015 AND <= 31/12/2015 but I […]

The name datetime is not permitted SQL Server

I am trying to insert the following query into my table insert into leave values (‘0101’, ‘ibrahim shaikh’, (datetime, ’26-11-2016′, 105), (datetime, ’26-11-2016′, 105), ‘1’, ‘nov’, ‘0’, ‘test’, ‘2016’, ‘0’, ’11’, ‘1’) but I am getting the error Msg 128, Level 15, State 1, Line 1 The name “datetime” is not permitted in this context. […]

Passing DateTime parameter to stored procedure using EF(DB first)

I created a stored procedure in SQL Server 2012 ALTER proc [dbo].[select_alltypes] @cdin_startunstufdate1 DateTime = null, @cdin_startunstufdate2 DateTime = null AS BEGIN SET NOCOUNT ON; SELECT 0 as shipid, i.cdin_cdindexid, p.pinv_PerformaInvID, coalesce(i.cdin_serial, 0) as depno, coalesce(convert(datetime, left(convert(nvarchar, i.cdin_startunstufdate, 120), 10), 120),’-‘) as deidate, coalesce(i.cdin_goodsDesc, ‘-‘) as gooddesc, coalesce(i.cdin_Customdeclar, ‘-‘) as custdec, coalesce(i.cdin_NoofPackages, 0) as pkg, […]

SQL Server match two columns by different strings

So I have two tables: Expected: Id numberOfItems date And Reality: Id numberOfItems date And I want to get, for each month, sum of Expected.numberOfItems and sum of Reality.numberOfItems. The problem I have is that while Expected.date is a datetime, Reality.date is an int with a YYYYMM format. My guess is I need to match […]

Get certain weekday within a week given by a DATETIME

I need to pass one DateTime and DayOfWeek and from that I need to get DateTime of that selected week. –Sunday-1 –Monday-2 –Tuesday-3 –Wednesday-4 –Thursday-5 –Friday-6 –Saturday-7 DECLARE @DayOfWeek TINYINT = 1 DECLARE @Date DATETIME = ‘2016-07-21 23:47:11.133’ SELECT DATEADD(wk, DATEDIFF(wk,0,@Date), @DayOfWeek) for eg: for this, I need to get date like 2016-07-24 00:00:00 which […]

SQL Server: convert string 'n', 'hh', 'd' to global variables n, hh and d

We’re using a very high level framework, called Instant Developer, where Date Parts are implemented as strings. Implementing an interface, I added to the library of my project the function DATEADD (datepart , number , date ) from SQL Server. But when I call it, the generated code is, for example, SELECT dateadd(‘n’,90,CONVERT(datetime, DATEREQUEST+TIMEREQUEST)) FROM […]

How to get date time 01/03/2017 16:06:21 AM format in SQL Server

I am working on a query in SQL server 2012 where I need to get datetime format as 01/03/2017 16:06:21 AM. How do I do that?

How to check that given time slot is already exists in SQL Server 2012

I want to check the given start time and end time is between the start time and end time in SQLServer 2012. Case: I have a table, its having two column start time and end time with two rows, Please see below that is my table StartTime | EndTime 10:00:00 | 17:00:00 17:30:00 | 18:30:00 […]

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