Day/Month/Year date changed to Month/Day/Year in SQL - sql-server

I have an old Classic ASP application that was worked perfectly, recently it was moved to window server 2012 server with IIS 8.5, the problem is that I have a form to add record with Day/Month/Year format, when the date entered as 23/06/2015 in SQL will be added correctly as 23/06/2015 but when date entered as 01/06/2015 : 1st june 2015 in SQL will be added as 06/01/2015 Month/Day/Year which will be incorrect
I checked the location and date format for the server and it was dd/mm/yyyy, and the database didn't changed since the old server SQL 2008.
I searched the net and found the i need to change the IIS culture under GLOBALIZATION, but I don't know what to choose even if I chose my country still I am facing the same issue.

If you don't want to get into changing globalization and localization settings, the simple answer is to use the universal date input YYYYMMDD when inserting dates as strings.
Update
To expland on your comment: when changing the format of the date string in an insert/update query it does not change the format within the sql table itself.
e.g.
UPDATE [table]
SET [column] = '20150716 10:22'
WHERE Id = 7489
When viewed displays the same as the other records in the table:

Try this:-
https://www.webwiz.co.uk/kb/asp-tutorials/date-time-settings.htm
Add an entry into global.asa as below...
'When a session starts on the server the following code will be run
Sub Session_OnStart
'Set the server locale
Session.LCID = 2057
End Sub

Somethimes when nothing fix this problem (or a global solution could damage old scripts), A workaround that you could use is the convert function, to change the format in your stored procedure.
For Example:
select getdate() --prints 2018-10-05 12:24:43.597
select Convert(char(10),getdate(),103) --To force the date to be dd/mm/yyyy
And not leting the asp page to format the date, just print raw.

Related

Get date in date format from SQL Server

I have a table in SQL Server with a date column set to default date, however, when I fetch the data from the server using VBA I get the date column in string format. Is there any way I get the date as in date format?
Can you you advise how you are bringing in the data? EG from inbuilt connectors or via a recordset via VBA objects?
A quick hack which I wouldn't advise without really testing would be this :
Select DateDiff(DD, '1899-12-30', date_column) AS [column] from TABLE_x
What is this doing?
In Excel dates start 01-01-1900. When you change a date to 'General' you find it's actually a number with a format. The above date difference will give you the excel number version of the Date.
EG to get today 29/11/2019 which will be 43798 when cell format is 'General'.
Select DateDiff(DD, '1899-12-30', '2019-11-29') AS [column]
More info here
Non MS site explaining the situation
MS Office Info touching on the subject
Please note this basing your question on a SQL formatted date.

Importing Flat File into SQL Server stores incorrect dates In the database

I am a SQL student who has been tasked with loading data into SQL Server for a company that I intern with.
I have tried loading multiple flat files with dates formatted as 1/23/04 into SSMS and when going through the wizard the dates preview correctly. Once they're loaded into the actual database and a select query is performed, all dates return as 2023-01-04 format.
I'm not sure where to even begin to fix this. I've loaded columns as nvarchar(50) as opposed to date, datetime, and datetime2 to see if it would make a difference, and each case returns the same format. Is this a setting in the flat file, SSMS, or the computer itself?
In SSIS bring in the column (with the dates) as a string and add a derived column transform that will transform the column (using the substring function) to the correct date. SQL Server loves seeing dates as YYYY-MM-DD so that is why without explicitly telling it how to read the string it defaults to thinking that the inputted date is of that format.
If you are using SQL Server (SSMS) you should input it as a string (char(8)) and then use cast or convert functions to change the string into a date. You can then issue a 'Alter table drop column' to drop the string version column of the date.

SSAS - How to customize generated time dimension by SSAS wizard

I created a time dimension by using the SSAS wizard in Visual Studio.
It works well, however I would like to change the generated values for date values.
In fact, the finest granularity is the date formated as ", ".
monday, 01/01/2014
tuesday, 02/01/2014
...
I would like to replace them by format as the following example :
01/01/2014
02/01/2014
Any idea to do that ?
Finally I created a new view in SQL Server data source to customize my original table generated by SQL Server Dimension wizard.
This is the script to create the following view :
CREATE VIEW [dbo].[DimDateCustom]
AS
SELECT dbo.DimDate.*,
CONVERT(VARCHAR, [PK_Date], 103) AS formattedDate
FROM dbo.DimDate
You can change the last parameter for the CONVERT() function to change the destination format for the date (check Microsoft doc to get all codes)

Search By Date in SQL Server 2012

We just upgraded to SQL Server 2012 from 2005. While I'm a novice, something this simple couldn't be this difficult. I used to be able to pull data from a table based on the date vs date and time. As it now stands I have:
Select * from receipts_table where receipt_cancel_date = '2013-09-20'
before we upgraded this would work fine. How can I run this and actually get the desired results as I know there's receipts with a cancel date of 2013-09-20.
Thanx
If you are passing string for a date parameter, best format is ISO (yyyymmdd) format. Otherwise even though your string work in some servers it might not work in another depending on the culture of the server. ISO format is culture independent.
Also remove the time part from receipt_cancel_date column by converting it to a DATE (if DATETIME) for comparison purpose.
Try this:
Select * from receipts_table
where convert(date, receipt_cancel_date) = convert(date,'20130920')
Or use 120 style with your format:
Select * from receipts_table
where convert(date, receipt_cancel_date) = convert(date,'2013-09-20',120)

Why if I set "default language" in spanish the GETDATE() still formating the date in english?

why if I do this on my SQL-Server 2008:
EXEC sp_configure 'default language', 5
reconfigure
Where the date format is dd/mm/yyyy:
select * from sys.syslanguages where langid = 5
returns
dateformat
----------
dmy
So if I do
select GETDATE()
I'm waiting for something like:
(no column name)
----------------
31/08/2013 13:20:44.590
but I get:
(no column name)
----------------
2013-08-31 13:20:44.590
I'm using SQL-Server 2008 Express compatibility mode 100
ADDED:
My real problem is that I need to pass to Stored Procedures dates in dd/mm/yyyy hh:mm to DATETIME variables, but the parser is still waiting for yyyy-mm-dd although I change the default language.
Thank you
The following is going to be rendered by Management Studio, irrespective of server settings:
SELECT GETDATE();
This is returning a datetime value to the client application, NOT A STRING. If you want a string, you can explicitly convert to a specific style:
As for the input to your stored procedures, please, please, please pass proper datetime parameters and not strings. There is no reason to allow users to enter freetext like 6/9/2013 when you really don't know if they meant September 6th or June 9th. The safe formats to pass to SQL Server are:
YYYYMMDD HH:MM:SS.nnn
YYYY-MM-DDTHH:MM:SS.nnn
Anything else can be misinterpreted. Which is why you shouldn't handle these as strings anywhere except at the final step of presentation / display.
you can use like this
Select CONVERT(varchar(100), GETDATE(),103)+' '
+CONVERT(varchar(100), GETDATE(),108) as now
the result is

Resources