Learn how to a build a cloud-first strategyRegister Now


Date in format yyyyMMdd

Posted on 2011-10-14
Medium Priority
Last Modified: 2012-05-12
Hello all,

I have a legacy database from where I retrieve a field (INT) that is supposed to be a date, in the format yyyyMMdd, for example 20111014 for today.

What I need to know is if that date, let's say...

Dim DBdate as integer = 20111014

... is in between today minus 31 days range.

Is this possible?


Question by:pvg1975
  • 3

Expert Comment

by:Bill Nolan
ID: 36971991
Kind of silly for the dates to be stored that way.  Anyhow, use DateTime and TimeSpan.  You have to parse the int, something like this:

const int SillyDate = 20111014;

int year = SillyDate / 10000;
int month = (SillyDate - year) / 100;
int day = month % 1000;

DateTime date = new DateTime(year, month, day);
TimeSpan span = new TimeSpan(31, 0, 0, 0);

if (DateTime.Now - span)
   // bingo

Open in new window


Expert Comment

by:Bill Nolan
ID: 36972000
Change line 10 above to:
if (date > DateTime.Now - span && date <= DateTime.Now)

...technically, you probably should also set a local var dateNow instead of using the .Now property twice.

(Still don't know why I can't edit a post...)

Author Comment

ID: 36972014
Hi Slimfinger,

Line 8 killed me, Im working on VB instead of C#

Accepted Solution

Bill Nolan earned 2000 total points
ID: 36972020
It's trivial to convert it.  Look up TimeSpan on Google - the MSDN doc's usually give examples in different languages.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

810 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