Hi am trying to use the datetime.parse exact object in vb.net, but I keep getting an error saying invalid format. Here is my statement, could anyone tell me what I am doing wrong??
Dim TimeStart As Date
TimeStart = DateTime.ParseExact("2013.07.15-07:10:02", "yyyy.MM.dd-HH:MM:SS", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
The error is because the seconds must be lower case. Also, you're asking for the month twice. I suspect this is the format string you need:
yyyy.MM.dd-HH:mm:ss
Just as an informational bit, the upper case 'H' means it's looking for 24-hour time, instead of 12-hour time. Lower-case 'h' would mean 12-hour time. Here is the reference for custom datetime format string rules:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Related
Snowflake documentation says to use TO_DATE('2022-01-01', 'YYYYMM'), however, when running that I receive the error message:
"Error: too many arguments for function [TO_DATE("policy_effective_date", 'YYYYMM')] expected 1, got 2"
Any help is appreciated.
I was expecting to see 2022-01-01 turn into 202201. Even if I need to bring in DD that's fine too, I can just capture the LEFT 6 digits, but regardless the system is saying it's too many arguments.
TO_DATE() function accepts string/varchar format date and converts to Date Data type. For that we need to pass existing String date type format to parse. To Convert to the required format we need to use to_varchar as given in the documentation. https://docs.snowflake.com/en/sql-reference/functions-conversion.html
how can I convert the string "average_time_per_KM" to time in the formt of mm:ss?
I tryed using TIME and got an error 'Invalid time string "4:56"'Cast query to time format
is there a different function to cast in to mm:ss?
You can use any of below parse time that presented as string as minutes:seconds
PARSE_TIME("%M:%S", average_time_per_KM)
or
CAST(average_time_per_KM AS TIME FORMAT 'MI:SS')
You need to tell BQ what is the meaning of each digit in the string you give it.
For that you need to use the PARSE_TIME function:
SELECT PARSE_TIME("%M:%S", average_time_per_KM)
FROM `your.table`
I have tried everything that I can think of to get the right date format. Can anybody help with this RPA-problem in UiPath. I have used the 'get text' activity to get the folder date and after that tried to use the
Datetime.ParseExact(Str variable,"dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).
It gives me the error:
Assign: String was not recognized as a valid DateTime.
Your help is much appreciated.
edit: I have now sought help from a friend who figured it out. The error was in the string, which could not be seen, because there was an invisible character in the string that I extracted through 'get text' activity. The solution is in 2 steps:
assign another variable to the exact same date and use an if statement to find out if these two strings are equal and you will find out that they are not.
Now use a regex to capture only digits and slash/hyphen which will get rid of the invisible character.
Try to use "dd_MM_yyyy" instead of "dd/MM/yyyy".
The reason is because UiPath/VB.Net has a habit of using US date formatting even though you're using Culture Info...It's a real pain
Try this:
pDateString = "21/02/2020"
Assign a Date type variable = Date.ParseExact(pDateString,"dd/MM/yyyy",nothing)
Here we're telling the parser to use English format date...The Date type returned will be in US format but you can simply convert back to uk IF needed by using something like:
pDateString("dd/MM/yyyy")
Do any of you awesome DBA fellows know how to remove both the Date and Time stamp from an SQL string?
For example, I have a string that has this:
"2014-04-17 15:38:53.2389 Unexpected Failure System.ServiceModel.FaultException: Unexpected Failure"
I want to remove the "2014-04-17 15:38:53.2389" and just be left with this:
"Unexpected Failure System.ServiceModel.FaultException: Unexpected Failure"
I can get it to work using SUBSTRING
SUBSTRING(CAST([stacktrace] AS NVARCHAR(500)),25 ,LEN(CAST([stacktrace] AS NVARCHAR(500)))) as stackTrace
But this isn't very elegant and could cause problems for string that don't have dates at the start.
I can find ways to remove the TimeStamp or to remove the Date, but I can't find a way to remove both.
Any help would be much appreciated.
Thanks
I don't know the exact code, but: It should be possible to filter the string according to the first alphabetic letter in the string.
at least provide a generic format of your error like you are going to get date and timestamp or just time stamp or some text your error always start with
You can use as following:
check if it is date at start and design the substring accordingly under if-else
select isdate(convert(varchar(10),'2014-04-17 15:38:53.100',111))
possibly you can use as
if (select isdate(convert(varchar(10),<use substring to get first 25 values>,111)))=1
then <design substring to remove and use data>
else
<use as-is>
I'm facing problem while conversion of date
if I used -- Date.parse("28/01/2011")
it gives me error as
"String was not recognized as a valid DateTime."
so then I modify above code as -- CDate("28/01/2011")
it gives me error as
"Cast from string "28/01/2011" to type 'Date' is not valid."
I used convert.todatetime also date.parseexact but nothing is working...
I'm using VS2003 in asp.net1.1 with vb.net
Probably Parse is using InvariantCulture date format "MM/dd/yyyy". Maybe you can try with
DateTime.ParseExact("28/01/2011", "dd/MM/yyyy", CultureInfo.InvariantCulture)
or passing a correct culture on Parse, like spanish that has date format dd/MM/yyyy
Date.Parse("28/01/2011", new CultureInfo("es-ES", true));
Write from memory, maybe is not accurate