C# .NET - Passing Date value to SQL

Asked By suresh krishna on 29-Jun-12 07:40 AM
Earn up to 10 extra points for answering this tough question.
 SQL server Date culture is  UK Culture.....

How to pass the date value from c - sharp ?

C D replied to suresh krishna on 30-Jun-12 01:49 AM

Hi Frndz,

 

Functionality:  Pass Date value dd/mm/yyyy to Sql server

 

 

To achieve this task,

 

First set Culture in UK format

 

CultureInfo MyUsersCulture = Thread.CurrentThread.CurrentCulture;

 

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

 

After then Parse to Date in dd/mm/yyyy format ( your string Date must be in dd/mm/yyyy format)

 

   DateTime dtTemp = DateTime.ParseExact(dateString, "dd/MM/yyyy", null);

 

Now Store dtTemp Value to DB table

 

 

 

Full Logic     :

 

 

        CultureInfo MyUsersCulture = Thread.CurrentThread.CurrentCulture;

        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

        string dateString = "30/12/2012";

        // in order not to have to specify a FormatProvider

        DateTime dtTemp = DateTime.ParseExact(dateString, "dd/MM/yyyy", null);

 

 

 

Hope this helpful!

Thanks

 

 

 

[)ia6l0 iii replied to suresh krishna on 01-Jul-12 09:46 AM
Although there are many ways of achieving this, the best way to do this is to store the UTC date time in SQL Server database. Do your regional transactions in the client or the service side. Do not store non-UTC values in SQL Server.
suresh krishna replied to C D on 02-Jul-12 04:47 AM
Thanks a lot ......
 Its works me
Kamal Ramavat replied to suresh krishna on 26-Dec-12 09:02 AM

To get current date in c# use DateTime.Now.ToString()............ there is also some different methods under Now.... use what is appropriate for u .

first u must have to set date value in UK culture.... then

if u r using a procedure it is easier..... say proc. name  saveCurrentDate

String s=DateTime.Now.ToString(); 

String queryString="saveCurrentDate '"+s+"'"; //// or String queryString="insert int myTable(mydate) values ('"+s+"')";

 

hope it will hellped u

help
Hi All, How we will know on which date sql server 2000 sp4 installed on that server? Is that sp4 update date get stored
i want to retrieve server date. how it should be retrieved using SQL server may be using Stored procedure . function would give you current date and time. use SELECT
my sql2000sp4 on winsbs2k3 stoped working due to error access is denied (error 5). It worked well during two years until yesterday. any ideas? sql service manager starts with domain / administrator. SQL Server Discussions SQL Server 2000 (1) Stored procedure (1) Errorlog (1) Backup (1) Class (1) Lock (1) Date
I was just saying today that sql server is full of silly limitations and I seem to hit on a new one every features with more ways to manipulate things than you can poke a stick at. In sql server we don't even have a full range of date functions (a pretty basic feature
Hello. Our SQL Server 2000 database is running on Windows 2000 Server and was wondering if anyone knew if the new Daylight Savings Time rule will affect any date functions in sql server like in the stored procedures? Thanks in advance. J SQL Server
We used to have automatic scheduled task to backup the LCS Standard edition (running on SQL Desktop Edition). However, it looks like it hasn't been backing up the database for run the command directly, i get the following: - -- -- -- -- -- -- -- -- -- -- C: \ > "C: \ Program Files \ Microsoft LC 2005 \ Server \ Support \ dbbackup.exe" / backupfile:"C: \ LC \ LC Backup" Connecting to SQL Server. . . Performing backup. . . Error: Failed to backup database. SQL Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'mirror_count'. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name
I recently installed SQL Server 2008 Express Edition with Advanced Tools. This is the version information from SQL Server Management Studio Microsoft SQL Server Management Studio 10.0.1600.22 ((SQL_PreRelease).080709- 1414 ) Microsoft
Does anyone know of an integrated change management solution for Sql Server? SQL Server does a crappy job of tracking changes. It doesn't even give you the last
explain the differences between oracle and sql server SQL Server is MicroSoft Product Oracle is Multinational Company am not asking about the companies, sql server
I am using SQL Server 2005. I have the option to store a Tiff image inside SQL Server or In the file system. I have 15, 000 images per day. I have the