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

Date assembly

I have data stored in an array in this format:
Str(0) = "AUG"
Str(1) = "10"
Str(2) = "13:44:38" (24 Clock)

I need to re-assemble this into a valid date variable. What is the
best algorythm to do this?

Right now I'm converting AUG to an 8 and then 10 to a day and assuming
that the year is always 2005.

8/10/2005 13:44:38

There has to be a better way...?

Nov 21 '05 #1
3 946
"pmclinn" <pm*****@gmail.com> schrieb:
I have data stored in an array in this format:
Str(0) = "AUG"
Str(1) = "10"
Str(2) = "13:44:38" (24 Clock)

I need to re-assemble this into a valid date variable. What is the
best algorythm to do this?

Right now I'm converting AUG to an 8 and then 10 to a day and assuming
that the year is always 2005.


\\\
Dim str(2) As String
str(0) = "AUG"
str(1) = "10"
str(2) = "13:44:38"
MsgBox( _
Date.ParseExact( _
str(1) & " " & str(0) & " 2005 " & str(2), _
"dd MMM yyyy HH:mm:ss", _
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

perhaps this would do what you want (you assume what you will about the
year):

Dim dateSegments As String() = {"AUG", "10", "13:44:38"}

ReDim Preserve dateSegments(dateSegments.Length)

dateSegments(dateSegments.GetUpperBound(0)) = Now.ToString("yyyy")

Dim derivedDate As Date = CDate(String.Format("{0} {1}, {3} {2}",
dateSegments))

Console.Write(derivedDate.ToString("MM/dd/yyyy HH:mm:ss"))
Nov 21 '05 #3
On 11 Aug 2005 10:25:51 -0700, pmclinn wrote:
I have data stored in an array in this format:
Str(0) = "AUG"
Str(1) = "10"
Str(2) = "13:44:38" (24 Clock)

I need to re-assemble this into a valid date variable. What is the
best algorythm to do this?

Right now I'm converting AUG to an 8 and then 10 to a day and assuming
that the year is always 2005.

8/10/2005 13:44:38

There has to be a better way...?


Well, the assumption of the year is a big problem that you will need to
decide what the RIGHT thing to do is. If today were 1 Jan 2006 and you are
handed the strings above, do you *want* it to assume 2006, or 2005, or
what?

A way to assume the current year, rather than 2005, is to substitute
Year(Now) for 2005 in your existing code.

Now ... a way to turn a string into a date value when you are positive you
know the format, is the method Date.ParseExact. I ran this in the debugger
(just paused at a breakpoint in one of my own programs and typed this in
the Command Window):

? date.ParseExact("10 AUG 13:44:38","dd MMM HH:mm:ss",nothing)
#8/10/2005 1:44:38 PM#

From what I can determine, the absent year in that string is going to be
assumed to be the current year - again, that may or may not be what you
want.
Nov 21 '05 #4

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

Similar topics

8
by: Michael A. Covington | last post by:
Is there a way to make a C# program print the date on which it was compiled? Finding the file date of the executable is one way, but it's not foolproof. Thanks!
5
by: cameron | last post by:
Is it possible to get the build date, (not the version), of a dll? -Cam
3
by: Just D. | last post by:
We all know hot to get the Assembly name and version. Can we get the assembly compilation date and how can we get this datetime if it's possible? It's not a very good idea to get the file DateTime...
3
by: Jesper | last post by:
Hi, In c++ ( I do no longer remember exactly how) I used some compiler predefined macro to insert the date and time of compilation into a string. How is this done in c# In c++ it could have...
2
by: Roger Helliwell | last post by:
Hey gang, What's the best way to implement a Build version (or "last updated" date) in my web-app? I have a footer in my master page that displays the application's name and copyright info etc....
3
by: Tim | last post by:
Hi, The following code works just fine in VS 2003 but in VS 2005 I am getting an error: The code: DateTime dClose = System.Convert.ToDateTime(now.Date.ToString("MMM dd, yyyy") + " " +...
4
by: IdleBrain | last post by:
Hello All, Is it possible to obtain the last Modified date for the source code from within the application? If yes, please let me know how it is done.
10
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
2
by: Dylan Parry | last post by:
Hi, Is there a way of getting the date that an assembly was last compiled? I am trying to help myself to remember what version of a particular assembly my Web applications are using, so I've...
2
by: Pieter | last post by:
Hi, How can I knwo the BuildDate from an application distributed by ClickOnce? When I use "System.IO.File.GetLastWriteTime(objAssembly.Location)" or...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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...

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.