Solved

DateTime Format YYYYmmDD

Posted on 2013-06-13
3
610 Views
Last Modified: 2013-06-14
How do I get a DateTime object in format YYYYmmDD.
E.g. for Jan 2, 2013 -> 20130102
0
Comment
Question by:allelopath
[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
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
gt2847c earned 375 total points
ID: 39246074
This link gives you all of the formats

This should also do it:

myDateTimeVar.ToString("yyyyMMdd")
0
 

Assisted Solution

by:Eamun
Eamun earned 125 total points
ID: 39246085
From MSN:
http://msdn.microsoft.com/en-us/library/efez4684.aspx

When you return the numbers, do you still need them as an int?
You can use:
DateTime currentDT = DateTime.now;
int dtObject = currentDT.Year * (Math.Pow(10,4)) + currentDT.Month * (Math.Pow(10,2) + currentDT.Day

This should shift the numbers to YYYYMMDD format.
0
 
LVL 9

Assisted Solution

by:gt2847c
gt2847c earned 375 total points
ID: 39246094
A much simpler method:

var myInt = int.Parse(myDateTimeVar.ToString("yyyyMMdd"));
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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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