?
Solved

Date Formatting

Posted on 2008-10-16
11
Medium Priority
?
266 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
[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
  • 3
  • 3
  • 3
  • +1
11 Comments
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 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