Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:39:33+00:00 2026-06-12T17:39:33+00:00

Possible Duplicate: DateTime.ParseExact format string How do I convert a string to a DateTime

  • 0

Possible Duplicate:
DateTime.ParseExact format string

How do I convert a string to a DateTime object?

Example:

Sun Oct 07 2012 00:00:00 GMT+0500 (Pakistan Standard Time)

I have tried, DateTime.Parse, Convert.TODateTime, etc. None work. I get an error that it is not a valid DateTime string.

Here is how I am sending datetime to MVC controller’s action method from jquery:

$.ajax({
        url: '@Url.Action("actionMethodName", "controllerName")',
        type: "GET",
        cache: false,
        data: {
               startDate: start.toLocaleString(),
               endDate: end.toLocaleString()
         },
         success: function (data) {
         }
});

I need to be able to get the datetime back in the controller action method:

public JsonResult actionMethodName(string startDate, string endDate)
{
        if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
        {
            var start = DateTime.Parse(startDate); //Get exception here
            var end = DateTime.Parse(endDate);     //Get exception here 
        }

        //Rest of the code
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:39:34+00:00Added an answer on June 12, 2026 at 5:39 pm

    I would recommend you to use the .toJSON() method on your javascript Date instances in order to serialize them as ISO 8601 format:

    $.ajax({
        url: '@Url.Action("actionMethodName", "controllerName")',
        type: "GET",
        cache: false,
        data: {
            startDate: start.toJSON(),
            endDate: end.toJSON()
        },
        success: function (data) {
        }
    });
    

    Now you don’t need to be parsing anything in your controller, you will be working with dates directly:

    public ActionResult ActionMethodName(DateTime startDate, DateTime endDate)
    {
        //Rest of the code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Convert Date String to DateTime Object in Python Is there an easy
Possible Duplicate: How can I convert string to datetime with format specification in JavaScript?
Possible Duplicate: Convert string to DateTime in c# A question I got a string
Possible Duplicate: Convert string to DateTime in c# I am trying to convert a
Possible Duplicate: Format mysql datetime with php How to convert the following: 2010-12-07 12:00:00
Possible Duplicate: Format mysql datetime with php I want to calculate for example 10
Possible Duplicate: How to convert DateTime object to dd/mm/yyyy in C#? I'm new to
Possible Duplicate: How to convert DateTime to VarChar Example How do you convert a
Possible Duplicate: Convert a datetime.date object into a datetime.datetime object with zeros for any
Possible Duplicate: Format mysql datetime with php Well.. I have stored date(c) in Mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.