?
Solved

Format date in string

Posted on 2007-11-25
5
Medium Priority
?
240 Views
Last Modified: 2011-01-13
I am applying content of a date field to a text field as a string, on a from. Data in the date field is in the long date format e.g. 7/20/2007 12:07:00 PM. I do not want the time information (12:07:00 PM) in the text field. How can I eliminate it from the string? Cannot change the date format in the underlying table, as it is transmitted data. Changing the date format (to short date) on the form did not help.
0
Comment
Question by:ChuckRaine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 20345732
a datetime variable has a ToString() method, which can accept a format parameter.
http://articles.techrepublic.com.com/5100-3513-6106789.html
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 100 total points
ID: 20345770
having the date/time stored in a string, you can extract the date in many ways:

Dim justdate as String
justdate = fulldate.Substring(0, fulldate.IndexOf(" "))
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 200 total points
ID: 20345833
> Data in the date field is in the long date format

That is not completely correct. The data in the field doesn't have a format at all. When you convert the data to a string in order to display it, the conversion uses a specific format.

If you don't specify any format for the conversion, the date format of the current culture is used. You can specify the format in serveral ways, and use different ways of converting the value, depending on the format you want. Some examples:
theField.Text = theDate.ToShortDateString()
theField.Text = theDate.ToLongDateString()
theField.Text = theDate.ToString("d") 'short date
theField.Text = theDate.ToString("D") 'long date
theField.Text = theDate.ToString("M/d/yyyy") 'custom format
theField.Text = String.Format("{0:d}", theDate)
theField.Text = String.Format("{0:D}", theDate)
theField.Text = String.Format("{0:M/d/yyyy}", theDate)

Open in new window

0
 
LVL 11

Assisted Solution

by:AkisC
AkisC earned 100 total points
ID: 20350262
Another suggestion ...
        Dim theDate As Date = Now()
        MsgBox(theDate)
        theDate = DateSerial(Microsoft.VisualBasic.DateAndTime.Year(theDate), Microsoft.VisualBasic.DateAndTime.Month(theDate), Microsoft.VisualBasic.DateAndTime.Day(theDate))
        MsgBox(theDate)
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20351214
@AkisC:

Are you kidding? I don't think that I have seen a more complicated way of writing:

theDate = theDate.Date

;)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

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