Solved

Format date in string

Posted on 2007-11-25
5
238 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 25 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 25 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 50 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 25 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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