Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Format date in string

Posted on 2007-11-25
5
Medium Priority
?
243 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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…

609 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