1
 This is the query string that I am receiving in URL.

 Output url: /demo/analysis/test?startDate=Sat+Jun+01+2013+00%3A00%3A00+GMT-0700+(Pacific+Daylight+Time)&endDate=Fri+Sep+13+2013+00%3A00%3A00+GMT-0700+(Pacific+Daylight+Time)

 test controller:
 Public Function GetData(<FromUri()> ByVal query As Request) As HttpResponseMessage
 {
 }

 Request{
 public DateTime StartDate { get; set; }
 public DateTime EndDate { get; set; }
 }

Angularjs Api Code:

   exportFunt = function () {
            var query = generateExportData();
            Export(query);
        };


    function generateExportData() {
             return {
               startDate: viewModel.StartDate,
               endDate: viewModel.EndDate,
            };
        }

     Export: function (query) {

                $window.open('/demo/analysis/test?$.param(query), '_blank');
            }               
5
  • Are you asking for how to teach ASP.Net MVC to interpret dates in that format? Or are you asking how to adjust your javascript code to use a standardized format? If so, you'll need to show us that code. Commented Sep 16, 2013 at 15:38
  • Also, DateTime won't be sufficient. You are including an offset in your input, so you should use a DateTimeOffset type - or standardize your input to UTC. Commented Sep 16, 2013 at 15:40
  • I am adding these parameters through AngularJS codebase ....I will add that code just give me a sec... Commented Sep 16, 2013 at 15:52
  • @MattJohnson I have updated the javascript code... but I am not sure which is a standard format to pass datetime in the url so as the asp.net controller will be able to receive it.. Commented Sep 16, 2013 at 15:57
  • Are viewModel.StartDate and viewModel.EndDate JavaScript Date types? Or are they already strings at that point? Commented Sep 16, 2013 at 16:58

2 Answers 2

2

Since you don't require times, I'll assume that you are selecting whole calendar dates from some sort of date-picker. Simply pass your dates as strings in yyyy-mm-dd format:

function pad(n) {
  return n < 10 ? '0' + n : n;
}

function getDateString(dt) {
  return [dt.getFullYear(),pad(dt.getMonth()+1),pad(dt.getDate())].join('-');
}

function generateExportData() {
    return {
        startDate: getDateString(viewModel.StartDate),
        endDate: getDateString(viewModel.EndDate)
    };
}

Or if you don't want to write all of this yourself, you might consider using the excellent moment.js library:

function generateExportData() {
    return {
        startDate: moment(viewModel.StartDate).format('YYYY-MM-DD'),
        endDate: moment(viewModel.EndDate).format('YYYY-MM-DD')
    };
}
Sign up to request clarification or add additional context in comments.

Comments

0

I modified the Javascript sending the startDate & endDate in "mm/dd/yyyy" format. This worked as the asp.net controller method was able to get this dates in datetime type..

    exportFunt = function () {
        var query = generateExportData();
          query .startDate = [query.startDate.getMonth() + 1,
                         query.startDate.getDate(),
                         query.startDate.getFullYear()].join('/');
          query .endDate = [query.endDate.getMonth() + 1,
                         query.endDate.getDate(),
                         query.endDate.getFullYear()].join('/');
        Export(query);
    }; 

3 Comments

That's a very USA specific format. You should be using yyyy-mm-dd which is ISO8601 compliant. Also you are dropping the time and the time zone offset. Are these important to you?
Nope Time is not of much importance in this case. I know this is a sort of patch but not a permanent fix... Currently I don't know any other way to complete this task.. but I am still working on finding some good solution to this problem..
@MattJohnson thanks for your patience and time.... If you have any inputs for me to move ahead with another solution please let me know...thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.