• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

Javascript Time to C#/VB.net time

Hi There,

var today;
var currentDate;
today = new Date();
currentDate= new Date(today.getTime() - (2 * 86400000));

How to convert this javascript code into C# or VB.net

I tried using
Private currentDate As Date
currentDate = New Date(CLng(CDbl(today.TimeOfDay.ToString()) - 2 * 86400000))

but I got an exception.

Please advice.

0
theartha
Asked:
theartha
  • 2
1 Solution
 
effesCommented:
I hope I read this right and you want to "subtract" 2 days from the current point in time.
If that's the case, in C# you can write this:
DateTime currentDate = DateTime.Now.AddDays(-2);

Open in new window

VB should work in a similar fashion, but I don't usually do VB and can't check right now.

BTW: I think one of the reasons for the exception that you get is, that there is no type "Date" in .NET. Only "DateTime".
0
 
thearthaAuthor Commented:
Thank You.
0
 
effesCommented:
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now