0

I have a jquery request to asp.net method which provides 2 date string params:

qltyStartDT = "Tue Oct 30 07:00:00 PDT 2012"
qltyEndDT = "Mon Nov 12 16:00:59 PST 2012"

I am trying to convert to sql ready date format am using:

DateTime.TryParseExact(qltyStartDT, "", CultureInfo.InvariantCulture, DateTimeStyles.None, out QSDT);            
DateTime.TryParseExact(qltyEndDT, "", CultureInfo.InstalledUICulture, DateTimeStyles.None, out QEDT);

Trying to figure out what my date pattern should be? I would like to handle this is >net but if not doable I can try to parse out in JavaScript.

DaniDev
  • 2,471
  • 2
  • 22
  • 29

2 Answers2

0

If your date string were always in that EXACT format (i.e. a string of 28 characters), you could pass it to this function and return a date.

VB.NET

Private Function GetDate(ByVal sDateString As String) As Date
    sDateString = sDateString.Substring(8, 2) & " " & sDateString.Substring(4, 3) & " " & sDateString.Substring(24, 4) & " " & sDateString.Substring(11, 8)
    Return Date.Parse(sDateString)
End Function

C#

private static DateTime GetDate(string sDateString)
    {
        sDateString = sDateString.Substring(8, 2) + " " + sDateString.Substring(4, 3) + " " + sDateString.Substring(24, 4) + " " + sDateString.Substring(11, 8);
        return DateTime.Parse(sDateString);
    }

This ignores the time zone.

Guru Josh
  • 566
  • 8
  • 16
  • the problem is that I cannot ignore the time zone as it includes a shift in daylight savings i.e. PDT -> PST. I will resort to manually parsing date and adding or subtracting an hour as necessary but I am hoping I don't have to code all that logic as I am sure it's being handles somewhere – DaniDev May 02 '14 at 01:54
0

OK, so could not get TryParseExact to work so I re-formatted my Date string in Javascript to: (SQL pattern) "MM/DD/YYYY hhh:mm:ss"

JS: (note custom library) stackOverflow custom Library code: custom Library

function ParseDates(chartDate) { 
         var newDate = new Date(chartDate);
         //Folowing line requires implementation of custom code
         var custFormat = newDate.customFormat("#MM#/#DD#/#YYYY# #hhh#:#mm#:#ss#"); //("#YYYY#-#MM#-#DD#");
          return custFormat; 
    }

qltyStartDT = "MM/DD/YYYY hhh:mm:ss"

and used C#:

DateTime QSDT = DateTime.Parse(qltyStartDT)
DaniDev
  • 2,471
  • 2
  • 22
  • 29