Solved

Reduce this date trimming code

Posted on 2006-07-07
4
214 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 74
VS.net 2010 11 35
Handle KeyDown for ToolStripDropDownButton, ToolStripMenuItem 3 26
VB.Net - KeyPress Event 4 36
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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