Javascript Time to C#/ time

Posted on 2011-10-17
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

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

but I got an exception.

Please advice.

Question by:theartha
    LVL 6

    Accepted Solution

    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".

    Author Closing Comment

    Thank You.
    LVL 6

    Expert Comment

    You're welcome.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now