Solved

Date Formatting

Posted on 2008-10-16
11
257 Views
Last Modified: 2012-05-05
Hi, I'm using VB 2005, WinForms. I have a date field in one of my Access 2003 Database Tables that I show to my user via a Label on my Form. The date is formatted in the Access DB as "Short" (i.e. 99/99/9999), but when I retrieve it from the DB and pass the value to the Label, it shows up on my Form as "Date and Time" (i.e. 99/99/99 12:00 PM). How can I get rid of the "Time" part of the value?

Thanks,
Fulano
0
Comment
Question by:Mr_Fulano
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22737912
0
 
LVL 11

Expert Comment

by:melmers
ID: 22737923
Dim myDateTime As New Date(2008, 10, 17, 12, 0, 0)
Label1.Text = myDateTime.Date
0
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22737943
use date.tostring("specify format here")
0
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22737948
like date.tostring("HH:mm")
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22738024
assuming you have the date into a DateTime value, set your label text as:

yourlabel.Text = yourDate.ToShortDateString()
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Mr_Fulano
ID: 22738177
Maybe I should have provided the line of code I'm using to help you all with this.

This is how I'm getting the value out of the DB and into my Label.

lblPurchaseDate.Text = dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value.ToString

Hope this helps you to help me further,
Fulano
0
 
LVL 11

Expert Comment

by:melmers
ID: 22738277

Dim myDate as Date(dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value.ToString)
lblPurchaseDate.Text = myDate.Date
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22740135
following my previous question:

lblPurchaseDate.Text = Convert.ToDateTime(dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value).ToShortDateString()

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22740146
sorry, I meant: following my previous answer...
0
 

Author Comment

by:Mr_Fulano
ID: 22747076
Thank you all for your help. I think you all did a great job at trying to help me, but in the end the best solution for my specific situation was provided by jaime_olivares, who suggested the following:

lblPurchaseDate.Text = Convert.ToDateTime(dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value).ToShortDateString()

This allowed me to keep my code as close to what I had it as possible while still solving the problem. The only thing I had to do is place the code in an IF statement to check for DBNull.Value like below and it worked well.

If Not (dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value) is DBNull.Value Then
lblPurchaseDate.Text = Convert.ToDateTime(dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value).ToShortDateString()
Else
lblPurchaseDate.Text = String.Empty
End If

In my specific situations, there may be cases where there is no valid date, so I needed to check.

Thanks,
Fulano

0
 

Author Closing Comment

by:Mr_Fulano
ID: 31507046
Nice coding...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now