.NET and TimeSerial from vb6

These two lines of vb6 code I am trying to translate to C#:

mskFromDate.Text = Format(Date - TimeSerial((iNumDaysBefore * 24), 0, 0), "Short Date")
    mskToDate.Text = Format(Date + TimeSerial((iNumDaysAfter * 24), 0, 0), "Short Date")

I have this so far. I know it is not right.

var dt = string.Empty;
                dt = Convert.ToString(DateTime.Now.ToOADate() - (NumDaysBefore * 24));
                this.dtFromDate.Text = Convert.ToDateTime(dt).ToShortDateString();

Anybody have thoughts? I can't believe in vb6 they let folks subtract dates and numbers.
Kelly MartensAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi Kelly,

I am not exactly following the VB6 code, but can you please give this one a try
this.dtFromDate.Text  = DateTime.Now.AddDays(NumDaysBefore * 24 *-1)).ToShortDateString();

Open in new window


Regards,
Chinmay.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
That VBA can be reduced to:

// Days to add/deduct.
int numDaysBefore = 2;

mskFromDate.Text = DateTime.Today.AddDays(-numDaysBefore).ToShortDateString();
mskToDate.Text = DateTime.Today.AddDays(numDaysBefore).ToShortDateString();

Open in new window

Kelly MartensAuthor Commented:
TimeSerial is throwing me off...
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Gustav BrockCIOCommented:
Not sure what you mean - but the original code could have been reduced as well:

mskFromDate.Text = Format(DateAdd("d", -iNumDaysBefore, Date), "Short Date")
mskToDate.Text = Format(DateAdd("d", iNumDaysAfter, Date), "Short Date")

Open in new window

Kelly MartensAuthor Commented:
Thank you all.
Gustav BrockCIOCommented:
You are missing something. That "solution" will add NumDaysBefore * 24 days, not NumDaysBefore days.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.