?
Solved

Javascript Time to C#/VB.net time

Posted on 2011-10-17
3
Medium Priority
?
501 Views
Last Modified: 2012-05-12
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
Comment
Question by:theartha
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
effes earned 2000 total points
ID: 36982282
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
 

Author Closing Comment

by:theartha
ID: 36982515
Thank You.
0
 
LVL 6

Expert Comment

by:effes
ID: 36982580
You're welcome.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

807 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