08:15:16 April 1, 2010 PDT
I need to save this to DateTime in MSSQL database but I can't convert this in C#. Can somebody help me to cast it? And what the hell is 'PDT
'?
Asked
Active
Viewed 645 times
2

1110
- 7,829
- 55
- 176
- 334
-
2how does your code look so far? what happens when you try to use a parse method? – Nicolas78 May 23 '11 at 08:30
-
1PDT – Pacific Daylight Time is a time zone. – Ruben May 23 '11 at 08:32
-
be careful with the timezone, that is the tricky part of this question – tofutim May 23 '11 at 08:33
-
This might be relevant for you http://stackoverflow.com/questions/2580356/parsing-rfc1123-formatted-dates-in-c-net-4-0 – V4Vendetta May 23 '11 at 08:43
2 Answers
2
This post is related to Parse DateTime with time zone of form PST/CEST/UTC/etc
I'm not sure how to get from alpha timezone to numeric, but after you do that you can
DateTime myDate = Convert.ToDateTime("Thu, 18 Mar 2004 14:52:56-07:00");
Update: This link apparently contains code to do the "PDT" to GMT offset conversion. http://bytes.com/topic/c-sharp/answers/214648-how-do-i-parse-date-w-time-zone Also check out the TimeZoneInfo class http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx
-
I used code from http://bytes.com/topic/c-sharp/answers/214648-how-do-i-parse-date-w-time-zone and I think it works fine. Actually it is important to cast that PDT to +0700 and than it works. If there is any problem I will reopen question but for now it work. Thanks – 1110 May 23 '11 at 13:04
1
The code in this post seems to work fine: http://www.codeillustrator.com/2010/03/converting-paypal-paymentdate-to-net.html
using System;
using System.Globalization;
public static class PayPalTransaction
{
public static DateTime ConvertPayPalDateTime(string payPalDateTime)
{
// accept a few different date formats because of PST/PDT timezone and slight month difference in sandbox vs. prod.
string[] dateFormats = { "HH:mm:ss MMM dd, yyyy PST", "HH:mm:ss MMM. dd, yyyy PST", "HH:mm:ss MMM dd, yyyy PDT", "HH:mm:ss MMM. dd, yyyy PDT" };
DateTime outputDateTime;
DateTime.TryParseExact(payPalDateTime, dateFormats, new CultureInfo("en-US"), DateTimeStyles.None, out outputDateTime);
// convert to local timezone
outputDateTime = outputDateTime.AddHours(3);
return outputDateTime;
}
}
(answer cross-posted for this similar question: How do I convert Paypal's HH:MM:SS DD Mmm(.) YYYY PST/PDT to a C# UTC DateTime?)

Community
- 1
- 1

Antoine Leclair
- 17,540
- 3
- 26
- 18