PC Review


Reply
Thread Tools Rate Thread

Date assembly

 
 
pmclinn
Guest
Posts: n/a
 
      11th Aug 2005
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...?

 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Aug 2005
"pmclinn" <(E-Mail Removed)> 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/>
 
Reply With Quote
 

Guest
Posts: n/a
 
      11th Aug 2005
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"))


 
Reply With Quote
 
Ross Presser
Guest
Posts: n/a
 
      11th Aug 2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Assembly date Jesse Houwing Microsoft C# .NET 0 25th Jan 2010 09:09 PM
Getting date of assembly compilation Dylan Parry Microsoft C# .NET 2 14th Jun 2006 05:50 PM
Assembly date ? Just D. Microsoft C# .NET 2 24th Jul 2005 06:42 AM
Assembly Build Date/Time Zack Sessions Microsoft VB .NET 1 24th Jun 2004 06:10 PM
information about assembly date codymanix Microsoft C# .NET 1 28th Oct 2003 12:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:11 AM.