473,396 Members | 1,816 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.

Parse Date

Hi,
I have some data in the format of yyyymmdd (Int32) that I want to display,
in a datagrid, formatted in International Date Format dd MM yyyy.

Any suggestions on an efficient approach?

Thanks,

Doug
Nov 21 '05 #1
5 2232
"Doug Bell" <Po*********@vodaphone.com.au> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
I have some data in the format of yyyymmdd (Int32) that I want
to display in a datagrid, formatted in International Date Format

dd MM yyyy.

Dim i as Integer _
= <value in form yyyymmdd>
Dim d as DateTime _
= CDate( i.ToString( "0000\-00\-00" ) )
DoSomethingWith( d.ToString( "dd MMM yyyy" ) )

HTH,
Phill W.
Nov 21 '05 #2
Thanks Phil, that is fine for taking a value from a single record and
converting it but I was looking for a way to display the whole datatable in
a datagrid.

Doug

"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:dd**********@yarrow.open.ac.uk...
"Doug Bell" <Po*********@vodaphone.com.au> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
I have some data in the format of yyyymmdd (Int32) that I want
to display in a datagrid, formatted in International Date Format

dd MM yyyy.

Dim i as Integer _
= <value in form yyyymmdd>
Dim d as DateTime _
= CDate( i.ToString( "0000\-00\-00" ) )
DoSomethingWith( d.ToString( "dd MMM yyyy" ) )

HTH,
Phill W.

Nov 21 '05 #3
Doug

What is the datasource if it is a table than you can maybe add an extra
table column.

Than you can use this code in a for loop to fill that extra column.

Dim intdat As Integer = 20050808 'creating your integer and trying to see if
I understood you.
Dim intString As String = intdat.ToString
Dim myDate As DateTime = DateTime.ParseExact(intString, "yyyyMMdd", Nothing)

However you are direct in trouble when you want to add a row because you
cannot set this in an expression.

I hope this helps,

Cor
"Doug Bell" <Po*********@vodaphone.com.au> schreef in bericht
news:Or**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have some data in the format of yyyymmdd (Int32) that I want to display,
in a datagrid, formatted in International Date Format dd MM yyyy.

Any suggestions on an efficient approach?

Thanks,

Doug

Nov 21 '05 #4
Thanks Cor,
I was hoping to find a way to parse or format the field but adding a column
is an acceptable solution.

Doug

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:e1**************@tk2msftngp13.phx.gbl...
Doug

What is the datasource if it is a table than you can maybe add an extra
table column.

Than you can use this code in a for loop to fill that extra column.

Dim intdat As Integer = 20050808 'creating your integer and trying to see if I understood you.
Dim intString As String = intdat.ToString
Dim myDate As DateTime = DateTime.ParseExact(intString, "yyyyMMdd", Nothing)
However you are direct in trouble when you want to add a row because you
cannot set this in an expression.

I hope this helps,

Cor
"Doug Bell" <Po*********@vodaphone.com.au> schreef in bericht
news:Or**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have some data in the format of yyyymmdd (Int32) that I want to display, in a datagrid, formatted in International Date Format dd MM yyyy.

Any suggestions on an efficient approach?

Thanks,

Doug


Nov 21 '05 #5
Doug,
In addition to the other comments. I would recommend adding a second column
of type DateTime to your data table.

You could try using an Expression Column that converts from an Integer into
a Date.
http://msdn.microsoft.com/library/de...ssiontopic.asp

I would look at using modulus & division to split the int32 into year, month
& day, then use Convert & '+' to convert this into a string, and finally use
Convert to convert the string into a DateTime.

Seeing as how messy that formula might be, I would consider using a simple
for loop to update each row:
Something like (untested):
For Each row As DataRow in table.Rows
Dim yyyymmdd As Integer = DirectCast(row!yyyymmdd, Integer)
Dim yyyy As Integer = yyyymmdd \ 10000
Dim mm As Integer = (yyyymmdd \ 100) Mod 100
Dim dd As Integer = yyyymmdd Mod 100
row!theDateTime = New DateTime(yyyy, mm, dd)
Next

FWIW: I normally encapsulate the conversion from Integer to DateTime in its
own routine.

Alternatively I would consider using DataTable.Events to "compute" the
DateTime column, post if you want an example of this.

Hope this helps
Jay

"Doug Bell" <Po*********@vodaphone.com.au> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
| Hi,
| I have some data in the format of yyyymmdd (Int32) that I want to display,
| in a datagrid, formatted in International Date Format dd MM yyyy.
|
| Any suggestions on an efficient approach?
|
| Thanks,
|
| Doug
|
|
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Matteo | last post by:
Hy everybody. I'm not a html writer, but a sysadmin who's trying to help a user able to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1, Firefox 0.8+) due to a javascript date...
2
by: Samuel | last post by:
Hello, I am trying to convert a local time into UTC ISO8601, then parse it back into local time. I tried the following: ---------------------- #!/usr/bin/python import time import datetime...
3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
4
by: Muscha | last post by:
Hello, I have a date string in the following format: "2003-10-29T17:44+00:00" When I put it to DateTime.Parse() method it throws an exception, how do I parse this date format? Thanks, /m
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
3
by: Kevin Kenny | last post by:
Dear All, I have a date time validation method thus: public static bool IsDate(string date, System.IFormatProvider provider) { try { DateTime.Parse(date, provider) return true; } catch...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
3
by: Peter Duniho | last post by:
I'm sure there's a good explanation for this, but I can't figure it out. I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance, in which I'd replaced the...
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
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
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
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.