473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Change DateTime.Now format to ISO 8601

Hello guys,

I get this time from DateTime.Now "6/12/2009 11:45:28 AM" and I need to convert it ISO 8601 which is the one that SQL accepts "2009-12-06 11:45:28".

What can I do?
Jun 12 '09 #1
3 17675
I found a way to do this

Expand|Select|Wrap|Line Numbers
  1. DateTime lastTime = DateTime.Now;
  2. string x = lastTime.ToString("u").Replace("Z", "");
  3.  
but I need to do this in 1 step because I send this time by parameters, i,e:

Expand|Select|Wrap|Line Numbers
  1. Insert(DateTime.Now);
  2.  
And I would like to send the time through it
Jun 12 '09 #2
Plater
7,872 Expert 4TB
SQL server takes DateTime objects as a valid parameter. There should be no need to format the output string.

However, the .ToString() function has overloads which allows you to print out the date time exactly how you want it, check msdn on it
Jun 12 '09 #3
tlhintoq
3,525 Expert 2GB
@raulbolanos
Use the ToString method to format it however you like

Expand|Select|Wrap|Line Numbers
  1. DateTime.Now.ToString("YYYY-MM-dd hh:mm:ss");
Jun 12 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Esref Durna | last post by:
my sql server have this datetime format ( yyyy-mm-dd ) how could i change it to dd.mm.yyyy format thanks
2
by: Harikumar G | last post by:
Friends, My hardware sends me a date format like this 15:10:20.99 UTC Mon Oct 18 2004 I need to process this format and parse to a valid SQL datetime format, how can I do it more easily? My...
0
by: vooose | last post by:
Suppose you have a DataTable which is part of a DataSet that has a column of type DateTime. When you call ds.GetXml() the date comes out looking something like this: ...
2
by: Grey | last post by:
I use the DateTime format to change the date format, i.e. string a = "21/02/2004"; Convert.ToDateTime(a).ToString("MMMM dd, yyyy"); These two lines work well in my VS.NET development machine. But...
1
by: Ugur Ekinci | last post by:
Hi , I have two Sql Server 2000 on seperate machines , First one accepts datetime format like ("dd.MM.yyyy hh:mm:ss") And Second one accepts datetime format like ("MM.dd.yyyy hh:mm:ss") 1-...
3
by: INeedADip | last post by:
I have seen this problem posted all over, but have never ran across a solution.... I am serializing my dataset and they look like this: <NewDataSet> <xs:schema id="NewDataSet" xmlns=""...
1
by: Chill | last post by:
my sql server have this datetime format ( yyyy-mm-dd ) how could i change it to dd.mm.yyyy format thanks
1
by: mahendravishwa | last post by:
Hi, I want to change DateTime format in MySQL Database Table in dd/MM/yyyy format. Its possible so please provide guidance. Thanks
2
by: LukasMalik | last post by:
Hi all, in my application, I am using DateTime. Until I got in contact with SQL I did not try to solve this problem. Where is set DateTime format? Will somehow change application DateTime format...
3
by: Limno | last post by:
Hi, Can anyone suggest me, how to change the Date format in SQL. By Default it Creates datatype datetime as '0000-00-00 00:00:00'. But i want to change d format as Month/Date/Year. while Creating...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.