DATEDIFF working on yyyymmdd format SQL server -


why datediff accepts yyyymmdd format ? isnt yyyy-mm-dd format ?

the function datediff(datepart, start_date, end_date) working fine when dates in yyyymmdd format e.g.

datediff(day, 20161201, 20161231);  gives answer 30 

and if datediff(day, 20161201, 20161231) + 1 -- end date inclusive

it gives 31 

thanks,

aiden

this can bit hard tease out, explained in documentation, in section "supported string literal formats date".

there 5 sections on (but last 2 api specific). first section affected internationalization settings , has bunch of different formats.

the second iso 8601 format. think hyphenated format conflicts last format in first table ("yyyy dd mm" without hyphens).

the final section has informative line "a six- or eight-digit string interpreted ymd". hence, 'yyyymmdd' interpreted correctly. hence, unambiguous format date/time.

note: because functions using expect dates, if integer works, converted date using string representation. normally, date constants should in single quotes.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -