Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Date Formatting

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
Mr_Fulano
Asked:
Mr_Fulano
  • 3
  • 3
  • 3
  • +1
1 Solution
 
divyeshhdoshiCommented:
0
 
melmersCommented:
Dim myDateTime As New Date(2008, 10, 17, 12, 0, 0)
Label1.Text = myDateTime.Date
0
 
divyeshhdoshiCommented:
use date.tostring("specify format here")
0
Technology Partners: 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!

 
divyeshhdoshiCommented:
like date.tostring("HH:mm")
0
 
Jaime OlivaresSoftware ArchitectCommented:
assuming you have the date into a DateTime value, set your label text as:

yourlabel.Text = yourDate.ToShortDateString()
0
 
Mr_FulanoAuthor Commented:
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
 
melmersCommented:

Dim myDate as Date(dgvItems.Rows(intRowIndex).Cells("PurchaseDate").Value.ToString)
lblPurchaseDate.Text = myDate.Date
0
 
Jaime OlivaresSoftware ArchitectCommented:
following my previous question:

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

0
 
Jaime OlivaresSoftware ArchitectCommented:
sorry, I meant: following my previous answer...
0
 
Mr_FulanoAuthor Commented:
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
 
Mr_FulanoAuthor Commented:
Nice coding...
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now