Solved

Reduce this date trimming code

Posted on 2006-07-07
4
219 Views
Last Modified: 2010-04-23
There is always better and easier ways to do things and I think this code is probably proof.

What happens is I pull a date from a dataset and they are always formatted the same like this.

7/8/2005 12:00 PM
1/2/2004 12:00 PM
12/12/2006 12:00 PM

The 12:00 PM is always there and this is because the said datatable is pulled from a FOXPRO source with no time, so the 12:00 PM is a NULL time I guess. So before I push this into an SQL database I need to pull these 12:00 PM times out and push in a time field. Now this code does work perfectly but seems a little long.

Dim my_date As String = drfox("d_date").ToString
Dim my_time As String = drfox("d_time").ToString
my_date = my_date.TrimEnd("A"c, "P"c, "M"c)
my_date = my_date.Trim()
my_date = my_date.TrimEnd("1"c, "2"c, "0"c, ":"c)
my_date = my_date.Trim()
my_date = my_date & " " & my_time
drfox("d_date") = test
0
Comment
Question by:ParanoidOne
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17059490
Try this:

   Dim tempDate As Date = CDate(drfox("d_date").ToString()).ToString() & " " & drfox("d_time").ToString)
   drfox("d_date") = tempDate.ToString()

Bob
   
0
 

Author Comment

by:ParanoidOne
ID: 17060058
I think there was a small typo.

CDate((drfox

But other than that it worked beautiful !!!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17060218
I was coding in the comment block ;)

Bob
0
 

Author Comment

by:ParanoidOne
ID: 17060276
I figured you were :) Which I doubt I will ever be able to do.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending receiving text messages in vb.net 15 48
Help with preventing selection from a combobox 11 34
Iteration Help (Asp.net VB) 5 24
VB.net Open video relating to control 2 19
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question