473,786 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2250
"Doug Bell" <Po*********@vo daphone.com.au> wrote in message
news:Or******** ******@TK2MSFTN GP09.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*********@vo daphone.com.au> wrote in message
news:Or******** ******@TK2MSFTN GP09.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.ParseE xact(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*********@vo daphone.com.au> schreef in bericht
news:Or******** ******@TK2MSFTN GP09.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******** ******@tk2msftn gp13.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.ParseE xact(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*********@vo daphone.com.au> schreef in bericht
news:Or******** ******@TK2MSFTN GP09.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.Event s to "compute" the
DateTime column, post if you want an example of this.

Hope this helps
Jay

"Doug Bell" <Po*********@vo daphone.com.au> wrote in message
news:Or******** ******@TK2MSFTN GP09.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
43537
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 check. Let's go straight to the point: <script language="JavaScript"> alert("Date: "+Date.parse("2000-01-01"))
2
3755
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 import xml.utils.iso8601
3
4747
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 everything after and including the final / removed to end up with simply 8/3
3
35104
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
4424
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
3692
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 of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be writing okay, but it's failing to parse. I've tried changing the regional & language settings in my...
3
6824
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 (System.FormatException) return false;
5
5145
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. Could someone help me with the customization? Thanks. String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider...
29
2909
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
21276
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 DateTimeFormatInfo.FullDateTimePattern property with my custom format string: DateTimeFormatInfo dtfi = (DateTimeFormatInfo)DateTimeFormatInfo.InvariantCulture.Clone(); dtfi.FullDateTimePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
0
9650
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.