Liron Harel
Liron Harel

Reputation: 11247

Add number to the ending of a numerical date value in C#

I'm trying to store an ID with the Date (month/day/year) in the same integer value in C#.

This way I can check whether a specific Id was already voted on in a particular day and prevent double voting in the same day. I store the votes in a static variable.

I convert the date to long using this code:

long.Parse(DateTime.Now.ToString("yyyyMMdd"));

So for today (2/9/2015) I get: 20150209

Now my IDs are integers. I want to append those to the converted date number.

So if for example the ID is 138, I want to add 138 to the end of the number, so the end result would be: 20150209138.

How can I append the id to the converted numerical date like I've explained above?

Upvotes: 0

Views: 109

Answers (1)

apomene
apomene

Reputation: 14389

long.Parse(DateTime.Now.ToString("yyyyMMdd")+ID.ToString());

Upvotes: 4

Related Questions