472,796 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2432
"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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.