Vb.Net - Convert 8/21/2013 to YYYYMMDD

Good Day Experts!

I am "stuck" and have tried searching the net for assistance.

I have a date 8/21/2013 from my SQL Server db that I need to convert to YYYYMMDD.  The column in the database is defined as datatime.  Here is what I am doing so far:

Dim InvDate As Date
InvDate = rdrHdr.Item("Invoice Date")

When I am stepping through the code and hover over InvDate is get 8/21/2013.  How can I convert this to YYYYMMDD?

Thanks for the help,
jimbo99999
Jimbo99999Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ess KayEntrapenuerCommented:
InvDate.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture)

or rdrHdr.Item("Invoice Date").ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture)
0
käµfm³d 👽Commented:
I suspect that rdrHdr is a *DataReader, in which case you will need a bit of casting for sskayb2d's suggestion to work:

DirectCast(rdrHdr.Item("Invoice Date"), DateTime).ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture)

Open in new window


If not, then ignore my comment  = )
0
Monica PSoftware DeveloperCommented:
Try if this helps

Dim InvDate As Date
InvDate = rdrHdr.Item("Invoice Date")
MessageBox.Show(InvDate.ToString("yyyy-MM-dd"))

Open in new window


Dim InvDate As Date
InvDate = rdrHdr.Item("Invoice Date")
MessageBox.Show(InvDate.ToString("yyyyMMdd"))

Open in new window

0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

käµfm³d 👽Commented:
@AkilaPalanimuthu

Your suggestion is just a combination of esskayb2d's and my own comment (except you are relying on implicit type conversion).
0
Mel-Leo RosalCommented:
Dim InvDate As Date
InvDate = Format(rdrHdr.Item("Invoice Date"), "yyyy/MM/dd")

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo99999Author Commented:
Thanks everyone for your help.  It is working now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.