473,406 Members | 2,619 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,406 software developers and data experts.

ISO 8601 to Standard Date

80 64KB
Hey guys, I'm figuring out how I can convert an ISO 8601 to a standard DateTime like dd/mm/yyyy.

The string is:
Expand|Select|Wrap|Line Numbers
  1. 2013-01-03T00:00:00.0000000Z
And I'd want it to show it like so:
Expand|Select|Wrap|Line Numbers
  1. 03-01-2013
I'm storing this in an SQLite Database and the code I use to store everything:
Expand|Select|Wrap|Line Numbers
  1. conn.Open();
  2.  
  3.                                 command.Connection = conn;
  4.                                 command.CommandText = "insert into Test ([Date], [LogName], [Channel], [DateRecord], [SizeInBytes]) values" + "(@Date, @LogName, @Channel, @DateRecord, @SizeInBytes)";
  5.  
  6.                                 command.Parameters.Add("@Date", DbType.String);
  7.                                 command.Parameters.Add("@LogName", DbType.String);
  8.                                 command.Parameters.Add("@Channel", DbType.String);
  9.                                 command.Parameters.Add("@DateRecord", DbType.DateTime);
  10.                                 command.Parameters.Add("@SizeInBytes", DbType.Int64);
  11.  
  12.                                 foreach (DataGridViewRow row in dgvTable.Rows)
  13.                                 {
  14.                                     if (!row.IsNewRow)
  15.                                     {
  16.                                         command.Parameters["@Date"].Value = row.Cells[0].Value;
  17.                                         command.Parameters["@LogName"].Value = row.Cells[1].Value;
  18.                                         command.Parameters["@Channel"].Value = row.Cells[2].Value;
  19.                                         command.Parameters["@DateRecord"].Value = row.Cells[3].Value;
  20.                                         command.Parameters["@SizeInBytes"].Value = row.Cells[4].Value;
  21.                                         command.ExecuteNonQuery();
  22.  
  23.                                         btnGetDB.Enabled = false;
  24.                                         btnOpenLog.Enabled = false;
  25.  
  26.                                         txtFilterChannel.Enabled = false;
  27.                                         txtFilterDate.Enabled = false;
  28.                                         txtFilterLog.Enabled = false;
  29.                                         Application.DoEvents();
  30.                                     }
  31.                                     command.CommandType = CommandType.Text;
  32.                                 }
the Visual aspect is that I use a datagridview to see the data, so the conversion would have to happen while I read and store the data in the database.

Any help would be appreciated.

Michael
May 2 '13 #1
4 2359
Rabbit
12,516 Expert Mod 8TB
Correct me if I'm wrong but SQLite doesn't have any date data types. You have to use the functions they provide to convert to and either a string or numerical representation.
May 2 '13 #2
M1kkelZU
80 64KB
That is true but I'm not using SQLite functions to convert the dates. I've seen some examples of ISO to a standard date but for some reason I can't use them while importing and writing data to the database.
May 3 '13 #3
vijay6
158 100+
Hey M1kkelZU, you can use the following code to convert 'ISO 8601' date to normal date format. After this you can store the normal date in your database.

Expand|Select|Wrap|Line Numbers
  1. string isoDate = "2013-01-03T00:00:00.0000000Z";
  2.  
  3. int year = Convert.ToInt32(isoDate.Split('-')[0]);
  4. int month = Convert.ToInt32(isoDate.Split('-')[1]);
  5. int day = Convert.ToInt32((isoDate.Split('-')[2]).Split('T')[0]);
  6.  
  7. string Date = null;
  8.  
  9. Date = day < 10 ? "0" + day + "-" + (month < 10 ? "0" + month + "-" + year : month + "-" + year) : (day + "-") + (month < 10 ? "0" + month + "-" + year : month + "-" + year);
  10.  
  11. MessageBox.Show(Date);
May 3 '13 #4
M1kkelZU
80 64KB
ok thanks, I might have forgotten to mention that I'm reading the string from a file where I read and split each "cell" of data. But this helps with getting it started. Thanks :)
May 3 '13 #5

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

Similar topics

6
by: Jerome | last post by:
Hi, I know this is an old problem and I've already tried to look the solution up on the web but I didn't find what I need. So, there's the following situation: I've got an ASP page with a...
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
25
by: koray | last post by:
hi everyone, in my form i have to take some date information in dd-mm-yy format. but i don't want user to use tabs while typing. for example s/he should simply type 280104 but 28/01/04 must...
14
by: Steve Wright | last post by:
I am trying to validate if an entry on a form is a date. I have adapted code I found here http://www.codingforums.com/archive/index.php/t-14325 as below but I can't seem the get the results that I...
5
by: Dani | last post by:
Hi, I´m no superuser when it comes to MS Access. So I use MS Query to pull out info from an SQL database to Excel. I have a tabel containing different "titles" or "colums". One contains a date....
2
by: Papegoja | last post by:
Hi, A week ago I had a question how to get MS Query to return a standard date to a "YEAR-MONTH" (YYYY-MM) format. I received a great answer from Jerry Boone!!! It follows: SELECT...
2
by: Bill Nguyen | last post by:
I receive data in an XML file with the following date/time format. While I can parse the date & time using string function, I would like to know if this is some sort of datetime in SQLserver that I...
0
by: DKn | last post by:
How to do this in c#.Net If we passed the UTC value 20020219145216.000000480, it should return in this formate. date: 2/19/02 2:52:16 PM
2
chandru8
by: chandru8 | last post by:
Hi to all, I unable to solve this problem. Iam using vb6.0 anb msaccess 2003 Problem: Iam uploading data from various excel.The problem is with the date format only while uploading the date...
2
code green
by: code green | last post by:
I know this is simple but I have been using mssql for so long I have forgotten how to do it in MySql. I am reading a date from a CSV file of the format How do I convert this to ISO 8601 standard...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.