Solved

Reduce this date trimming code

Posted on 2006-07-07
4
194 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
Comment Utility
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
Comment Utility
I think there was a small typo.

CDate((drfox

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

Expert Comment

by:Bob Learned
Comment Utility
I was coding in the comment block ;)

Bob
0
 

Author Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now