Solved

Date Formatting

Posted on 2008-10-16
11
262 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 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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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