VB 2010 Convert UTC Date to dd-MMM-yyyy format - vb.net

I get the UTC Date and Time using:
Dim UTCN As Date = (Date.UtcNow)
It outputs 8/19/2012 3:48:24 PM
I need to FTP a file that must use the format dd-MMM-yyyy (19-Aug-2012)
My problem is that I must use UTC and it must be in the above format. This will run in various time zones so I do not want to use a fixed offset to convert local to UTC. I know how to FTP and everything else but I can not figure out how can I format UTCM to meet my needs?

Date.UtcNow.ToString("dd-MMM-yyyy")

Related

How to stop pandas converting some dates automatically when reading a csv

I have a csv, and one column is date, format dd/mm/yyyy.
I read it using z=pd.read_csv('property_scrape.csv')
My raw data is:
After I read it in, some of the values are kept in the format I downloaded (dd/mm/yyyy), while somewhere in the middle, the dates are converted to yyyy-mm-dd:
27 01/10/2019
28 01/10/2019
29 01/10/2019
...
21092 2020-08-22
21093 2020-08-22
21094 2020-08-22
Name: Date, Length: 21122, dtype: object
Does anyone know why this happens?
Also, is there a way to ensure that this date column is always read the correct/constant way?
The problem is Pandas samples the first row and thinks it is MM/DD/YYYY instead of DD/MM -- there isn't a real way to know this. Then later when it finds 22, which not a valid MM it defaults to object/string.
You can add flag infer_datetime_format=False and it should read as strings then you can parse it -- you can pass a lambda to read_csv as well, not sure if an easier way to just pass a format string -- see article article dsexchange 34357

Exception while try Date.ParseExact in VB.NET

I'm trying to parse this:
Date.ParseExact("5/19/2012", "M/d/yyyy", myCultureInfo)
In the machine with system date format MM/dd/yyyy, it works fine. But in machine with system date format dd-MMM-yyyy or any date format other than MM/dd/yyyy, it throws exception String was not recognized as a valid DateTime.. So how can I get my code above works regardless to system date format?
I found the solution
Date.ParseExact("5/19/2012", "M/d/yyyy", new Globolization.CultureInfo("en-GB")).toString(myCultureInfo)

Format a Date Time to the Full date/time pattern (short time) in Orchard

Within Orchard CMS (version 1.6) I have a Query that displays a DateTime property called StartDate. When setting it up I chose the "Full date/time pattern (short time)" as the Date format, and then I was rewriting the output as follows:
<My html text here> {Text}
This would render as "My html text here Saturday, April 13, 2013 2:30 PM".
I realized that for users on a different time zone, the date/time was being converted automatically and instead of displaying 2:30 PM (server is at PST), it was displaying 5:30 PM (user was at EST).
Following Bertrand Le Roy's solution here, it worked out nice with one minor issue.
Now my code is this:
<My html text here> {Content.Fields.MyContentType.MyDateTimeField.DateTime.Local}
And here is the result: "My html text here 4/13/2013 2:30:00 PM".
The formatting is not the one I would rather use.
Does anyone know how can I format this to the Full date/time pattern (short time)?
Thank you in advance.
{Content.Fields.MyContentType.MyDateTimeField.DateTime.Local.Format:dddd, MMMM d, yyyy h:mm tt} should do the trick.

VB.Net Date String Format Patterns

DateTime.Now to Jul 31 10:20:30 PST 2012 format
DirectCast(row(0), DateTime).ToString("ddd MMM dd HH:mm:ss 'PST' yyyy")
row(0) is a string that is in the format 7/29/2012 1:25:20 PM
Keeps telling me the cast is incorrect, how can I correctly cast the string?
Awesome link for patterns for datetime.
You should be using DateTime.Parse, DateTime.TryParse, DateTime.ParseExact or DateTime.TryParseExact.
I suspect you could use CType instead of DirectCast, but personally I'd go for the method call - it makes it clearer what you're doing.

Need to parse a string to date without padded 0's

I've read through a lot of examples, but the problem I'm facing is the date I'm getting doesn't have leading 0's and all the objective-c stuff I've found has them. So I need to take the date:
4/9/2012 1:30 PM
And determine if it is today. My place was to either grab today's date and compare it to the first part of that string, but as I said before I can't find anyway to make a date in objective c without leading 0's. I'm hoping to avoid parsing that string manually to add leading 0's.
Use an NSDateFormatter object
[dateFormatter setDateFormat:#"h:mm a"];
if you want 0's
[dateFormatter setDateFormat:#"hh:mm a"];
I think that using the single M option for your date format string will allow it to parse a single digit month value:
The possible date formats are specified here
#ynistersix answer is correct. In Data Formatting Guide, they said that NSDateFormatter follows http://unicode.org/reports/tr35/tr35-dates.html
h 1..2 11 Hour [1-12]. When used in skeleton data or in a skeleton
passed in an API for flexible date pattern generation, it should match
the 12-hour-cycle format preferred by the locale (h or K); it should
not match a 24-hour-cycle format (H or k). Use hh for zero padding.
This is consistent with most other languages. Like .NET
"h" The hour, using a 12-hour clock from 1 to 12.
2009-06-15T01:45:30 -> 1
2009-06-15T13:45:30 -> 1
"hh" The hour, using a 12-hour clock from 01 to 12.
2009-06-15T01:45:30 -> 01
2009-06-15T13:45:30 -> 01