Solved

DateTime Format YYYYmmDD

Posted on 2013-06-13
3
596 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now