Solved

DateTime Format YYYYmmDD

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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!
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 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