473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Converting into DateTime

Is there better way to convert integer type date into DateTime type date
as doing like code below?

Dim intDate As Integer = 20051019

Dim dte As DateTime = New DateTime( _
CType(intDate.ToString.Substring(0, 4), Integer), _
CType(intDate.ToString.Substring(4, 2), Integer), _
CType(intDate.ToString.Substring(6, 2), Integer))

--
Thanks in advance!

Mika
Nov 21 '05 #1
8 2469
"Mika M" <ma***************@luukku.com> schrieb:
Is there better way to convert integer type date into DateTime type date
as doing like code below?

Dim intDate As Integer = 20051019
I am curious why you are storing a /date/ as an integer. This is very
uncommon.
Dim dte As DateTime = New DateTime( _
CType(intDate.ToString.Substring(0, 4), Integer), _
CType(intDate.ToString.Substring(4, 2), Integer), _
CType(intDate.ToString.Substring(6, 2), Integer))


\\\
Dim dt As Date = Date.ParseExact(CStr(intDate), "yyyyMMdd", Nothing)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Is there better way to convert integer type date into DateTime type date
as doing like code below?


You can avoid the string allocations by doing something like this:

Dim dte As DateTime = New DateTime(intDate \ 10000, (intDate Mod 10000) \
100, intDate Mod 100))
Mattias

Nov 21 '05 #3
Mika,

I would probably do

Dim srtDate as String = 20051019.ToString

Dim dte As DateTime = New DateTime( _
Cint(strDate.Substring(0, 4)), Cint(strDate.Substring(4, 2)), _
Cint(strDate.Substring(6, 2))))

It is probably some parts of a nanoseconds faster however probably the same.

Cor
Nov 21 '05 #4
Herfried,

Better than my sample in this thread, (and I knew this one) donk donk.

:-)

Cor
Nov 21 '05 #5
Herfried K. Wagner [MVP] kirjoitti:
I am curious why you are storing a /date/ as an integer. This is very
uncommon.


I'm reading contents of CSV-file rows into DataTable. CSV-file contains
date values as strings that way, and I try to convert them into
DataTable's datetime field.
Nov 21 '05 #6
"Mika M" <ma***************@luukku.com> schrieb:
I am curious why you are storing a /date/ as an integer. This is very
uncommon.


I'm reading contents of CSV-file rows into DataTable. CSV-file contains
date values as strings that way, and I try to convert them into
DataTable's datetime field.


If you already have the values in string format,
'Date.Parse'/'Date.ParseExact' is the way to go. You can skip the step of
converting the string to an integer.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
Herfried,
| I am curious why you are storing a /date/ as an integer. This is very
| uncommon.
Its common to store a "date" as an "integer" on AS/400 databases & other
databases.

At least at the shops that have code pre-dating "date" fields being added to
their database systems.

I normally seen the dates stored as Decimal(9, 0) or Packed(9,0) rather then
an Integer (32-bit binary value).

--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
| "Mika M" <ma***************@luukku.com> schrieb:
| > Is there better way to convert integer type date into DateTime type date
| > as doing like code below?
| >
| > Dim intDate As Integer = 20051019
|
| I am curious why you are storing a /date/ as an integer. This is very
| uncommon.
|
| > Dim dte As DateTime = New DateTime( _
| > CType(intDate.ToString.Substring(0, 4), Integer), _
| > CType(intDate.ToString.Substring(4, 2), Integer), _
| > CType(intDate.ToString.Substring(6, 2), Integer))
|
| \\\
| Dim dt As Date = Date.ParseExact(CStr(intDate), "yyyyMMdd", Nothing)
| ///
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Nov 21 '05 #8
Herfried K. Wagner [MVP] wrote:
I'm reading contents of CSV-file rows into DataTable. CSV-file
contains date values as strings that way, and I try to convert them
into DataTable's datetime field.

If you already have the values in string format,
'Date.Parse'/'Date.ParseExact' is the way to go. You can skip the step
of converting the string to an integer.


Yes I did it directly from string to datetime - just asked question
differently using integer :)

Well... Now I'm wondering is it even possible to transfer those string
type days (like "20051020") to datetime format already at the same time
when reading CSV-file into DataTable-object using Provider
Microsoft.Jet.OLEDB.4.0 ?

--
Mika
Nov 21 '05 #9

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

Similar topics

3
by: Nikola | last post by:
Hi all, I have a problem converting datetime to integer (and than back to datetime). Depending whether the time is AM or PM, same date is converted to two different integer representations,...
3
by: sunny076 | last post by:
Hi, I am trying to convert from Julian to Gregorian data in C#. I was exploring teh JulianCalendar and Gregorian calendar classes but still not sure how I can do it. For example, the Julian date...
4
by: Saso Zagoranski | last post by:
Hi! I have created an SqlCommand object and I have set some parameters to it... One of the parameters is of the DateTime type; here is the code: sqlCommand.Parameters.Value =...
4
by: M. Uppal | last post by:
How do i convert fraction to time in c#. I need to convert 0.25 to time. Excel does this by using Selection.NumberFormat = "h:mm:ss;@" of the Cell Format function. thanks, M. Uppal
1
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub...
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
6
by: minboymike | last post by:
Hello everyone, I am working on a project when I have to convert a C# program into Native C for speed purposes. I am using a .dll that creates a DateTime object. Obviously, there is not...
2
by: joyjignesh | last post by:
hi i have make a report with mshflexgrid. the report between two date. when i have written query .open"select * from tablename where t_date>=convert(datetime,' " & text1.text &"') and ...
1
by: Matt | last post by:
Hi all, So a lot of digging on doing this and still not a fabulous solution: import time # this takes the last_modified_date naive datetime, converts it to a # UTC timetuple, converts that...
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
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
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.