Conversion of Datetime from server to another server - sql-server

I have SQL Server 2000 in both server. We have imported existing data to new server. And also we use vb application. Now we changing our data to new server. When we run application to retrieve date wise details it shows error
'The Conversion of Datetime to varchar is out of range'
And we pass our datetime from application is dd/mm/yy but values get inserted as mm/dd/yyyy. Is there any solution. please. thanks in advance

They are likely to be English and British English as mm/dd/yyyy and dd/mm/yyyy respectively.
Open the login properties under security in ssms object explorer on the new server and set it to British English.

You should check the default language of the login running the queries.
Probably is configured in English in the new server and not English (maybe Spanish?) in the old server.

Related

Wrong local date format saving to SQL Server with Laravel

Our code in Laravel receives a date in Y-M-D format and tries to save it to a SQL Server database.
The code receives these dates via APIs for many tables and we cannot change this functionality everywhere.
SQL Server language is italian and our code is OK with a Y-D-M date.
Is there a way to specify the date format once for all or the locale used in the database connection configuration?
Setting the language via statement doesn't work.
Our code is something like this:
DB::statement('SET LANGUAGE us_english');
DB::table('tablename')->insert($saveData);
I had the same problem writing on SQL Server.
It depends strictly on the language set in the database: https://database.guide/how-to-set-the-current-language-in-sql-server-tsql/
If the problem persists, you must check the user with which the database interacts and check the configuration, if it is different from the Administrator user, execute this command:
ALTER LOGIN your_login WITH DEFAULT_LANGUAGE = us_english
And then:
Carbon::now()->toDateTimeString();
You can convert date format to Italian using LARAVEL Carbon Date library.
Like below :
$date = carbon::now()->locale($yourLocale);
Here is the Carbon library locale example : https://carbon.nesbot.com/docs/#api-localization

azure web service app date format issue

Im developing an app thats hosted up in Azure. On my development machine when i edit and save dates (UK format - saving to local sql server 2012) theres no problem. When I deploy the same code base to Azure (same database structure & sql server version - db hosted in VM in Azure) Im getting an error
'the value 23/01/2014' is not valid for contract date
has anyone else experienced anything like this and could give me some pointers ?
Ive set the os on the VM machine to be uk region and the underlying dates in the tables both locally and remotely are exactly the same format. Is there anything obvious I could be missing ?
the value 23/01/2014' is not valid for contract date
Please run dbcc useroptions to check the language and dateformat. And by default, the date format for SQL server is in U.S. date format MM/DD/YY, unless a localized version of SQL Server has been installed.
You could try to use the international format YYYYMMDD for sending the datetime data to SQL Server or pass the date in date format being used on the SQL Server.

Fun with US and UK dates on a new server

I have just had the task of moving an old ASP website / SQL DB to a new dedicated OVH server (French - all defaults set to US-Eng).
The DB has moved from SQL 2005 to SQL 2012 (web edition 64 bit).
I am having the old issue of date formats showing up as US format on the website e.g 8/3/2016 instead of 03/08/2016. This is even though in the database they are stored as ISO Date 2016-08-03 etc.
I enter the dates on the ASP Classic, website as UK format
e.g. 03/08/2016 and convert them to ISO format 2016-08-03 in the SQL that is passed to the Stored Procedure that has SET DATEFORMAT YMD at the top of it.
If I check the tables in the DB they are all stored correctly as ISO dates.
I have made sure all the SQL Logins to the DB have "British English" selected as their "Default Language".
If I view the database properties under options the Default Language is British English.
If I view the server properties under General->Language it's English (United States) but under Advanced->Default Language it's British English.
The dates are getting stored as ISO correctly as if I do a DATEDIFF(DAY,Stamp,GETDATE())=0 I can see all the records even though they are showing up on the website as US format 8/3/2016 (Why there are no zeros in front of US dates I don't know).
The ASP code hasn't changed or the DB code it was just ported into this new dedicated server and now I am getting these issues. I am sure I solved something like this ages ago just by changing the default login language but that doesn't seem to work on this box.
I am getting lots of Primary Key/Index errors due to duplicate insertions due to the dates (mixing up US/UK) from a .NET app I have that uses the Betfair API to get racing data e.g
EXEC dbo.usp_net_insert_betfair_market_selection #MarketID = 125932808, #SelectionID = 10593225, #Racedatetime = '2016-08-03 15:10:00', #MarketType = 'WIN', #HorseName = 'She Done Good';
Violation of PRIMARY KEY constraint 'PK_BETFAIR_MARKET_SELECTIONS'. Cannot insert duplicate key in object 'dbo.BETFAIR_MARKET_SELECTIONS'. The duplicate key value is (719859, WIN, Mar 8 2016 3:10PM).
However if I copy that EXEC statement and run it direct in a query analyser window it runs WITHOUT ANY ERROR.
I have been searching the web and I have seen someone suggest putting this code at the top of all ASP pages that show dates to force it show in UK format > https://www.webwiz.co.uk/kb/asp-tutorials/date-time-settings.htm
'* Set the server locale to UK
Session.LCID = 2057
This has worked on SOME pages but I have never had to do this before.
On pages with long lists of records and dates in one column I have wrapped the date in CONVERT(varchar, GETDATE(),103) in the SQL and it returns correctly on the page.
I am confused though as I have never had to do this on the old set up and it seems like there must be some setting that needs to change to fix all this on the new server (SQL and Web IIS 8) on same box.
I have tried going into the .NET Globalization for the site and changing Culture and UI Culture to English (en). However that didn't fix everything.
The "Language" preferences on the machine are set to English (UK) although I wouldn't have though that would have made a difference.
If I run this code in a query analyser either RD into the box, or through my local SQL console connected to the machine over the network
select name ,alias, dateformat
from syslanguages
where langid =
(select value from master..sysconfigures
where comment = 'default language')
In a query window (Remote Desktop into server) I get back
Name Alias dateformat
British British English dmy
Question
So it seems like something to do with the connection between the ASP website or .NET app and the server/database. Something I have missed or need to change as this all worked fine on the old WebServer -> Database Server setup we had.
Is there something I have overlooked to ensure dates are shown as UK on the website without editing every ASP page and SQL that contains dates as I never had to do that for the old setup.

In SSRS, how do I force the reporting server locale from English-US to English-GB?

I have an issue where all dates in parameters are displayed as mm/dd/yyyy:
My goal is to change the date format to dd/mm/yyyy, which would require changing the locale to English-GB. Things which I've currently tried (and didn't work):
Changing the Language within the individual report settings to English-GB
Checking the Windows locale setting on the SQL Server instance (it was already set to English-GB and dd/mm/yyyy)
Changing the default SQL Server language using EXEC sp_configure 'default language', 23 ;
Changing the Reporting Server's service account language using ALTER LOGIN [XXXXX] WITH DEFAULT_LANGUAGE = British
Restarting the Reporting Service
Killing all connections to the SQL Server instance to force a reconnect
Non of the above worked and I'm still seeing the dates in the wrong format. Is there anything else I can do?
I think actually this comes from the Language of the browser rather than Report Server - I could be wrong. Try changing from US English to GB English in IE or whatever you're using.

Date format on reporting services

I installed SQL server and reporting services with him, when my regional settings is set to US, date format is been mm/dd/yyyy. Now, I changed region settings to German in tab Formats, Location and also System locale for non unicode programs.
My problem is that when I try to enter parameter for report, datetime format in report manager has same format like before mm/dd/yyyy. I try to re-create database for reporting services but with no luck.
I can not change application to send this us format to reporting services.
Windows server 2012 is OS.
Tnx...
There are a few things you can do:
You can try changing the Language on your report files (Properties - Location - Language) to match the same language on the database.
When you pass a parameter to a query, instead of using the parameter value, pass it as an expression like this: =Format(Parameters!Date.Value,"yyyyMMdd") which will convert it to a date format which will be accepted by any language setting on the database.
This got me for a while - finally found that you have to make sure the data type for the parameter (in the parameter properties) is set to datetime not text.

Resources