Exception while try Date.ParseExact in VB.NET - 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)

Related

How to using BigQuery PARSE_TIMESTAMP parse DateTime concat with underscore?

I have a time stemp formated as a string like this: 2022_05_26_13_52_05 which is format as YYYY_MM_DD_hh_mm_ss how can I use BigQuery PARSE_TIMESTAMP to parse it? I try it with
SELECT PARSE_TIMESTAMP("%Y_%m_%d_%I_%M_%S", "2022_05_26_13_52_05") from `Something.test.my_table_name_*`
It fails at: Failed to parse input string "2022_05_26_13_52_05", but if I only parse PARSE_TIMESTAMP("%Y_%m_%d", "2022_05_26"). It works perfectly fine. Many thanks!
try below instead
PARSE_TIMESTAMP("%Y_%m_%d_%H_%M_%S", "2022_05_26_13_52_05")
with result
2022-05-26 13:52:05 UTC

LogParser Query Expecting From Keyword Instead of Token 'To_Timestamp'

I am writing a query in LogParser Studio (and have also tried it in command line LogParser 2.2) in trying to find results that have a date between two specified dates in the query.
I get the error message (below) whenever I run it.
Error parsing query: Syntax Error: <from-clause>:expecting FROM keyword instead
of token 'TO_TIMESTAMP(date,time)' [SQL query syntax invalid or unsupported.]
Here is the query (below). Note that I do replace '[LOGFILEPATH]' with the actual path when I try this in the command line LogParser. The path to the log files is \inetpubs\logs\b\*.log
Also, I've tried removing the single quotes in the dates, with no positive results.
Thanks for your help.
SELECT LocalDateTime, USING TO_TIMESTAMP(date,time) AS LocalDateTime into
OUTPUT.CSV FROM '[LOGFILEPATH]' where LocalDateTime BETWEEN TIMESTAMP ('2012-01-06
13:50:00', 'yyyy-MM-dd hh:mm:ss') And TIMESTAMP ('2012-01-07 14:00:00', 'yyyy-MM-dd
hh:mm:ss') order by LocalDateTime DESC
I made some modifications to your query to fit my log. My log file doesn't have LocalDateTime so I change it to s-ip. I also removed into OUTPUT.CSV because there's another issue. I'm not sure if you have same issue. But it can work after remove it.
If you also have this issue, try to remove into OUTPUT.CSV .
So the issue is caused by USING TO_TIMESTAMP(date,time). If you want to use TO_TIMESTAMP function, just use it and no need to add USING.
Same error with you.
But it worked well after I removed the USING.

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 2010 Convert UTC Date to dd-MMM-yyyy format

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")

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.