Solved

Date Formatting

Posted on 2008-10-16
11
263 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
Independent Software Vendors: 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 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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