Mule changing the date format - mule

I am trying to convert date from "dd-MM-yyyy" format to "dd/MM/yyyy"
dob as Date {format: \"dd-MM-yyyy\"} as String {format :\"dd\/MM\/yyyy\"}
I am getting a dataweave parsing error. Please help

dob as Date {format: "dd-MM-yyyy"} as String {format :"dd/MM/yyyy"}

Related

convert dateTime to salesforce required dateTime format in mule 4

For the dateTime "2022-11-29T19:12:21Z" getting INVALID_TYPE_ON_FIELD_IN_RECORD error from salesforce. So need to convert it in correct format that Salesforce accept.
Input: "2022-11-29T19:12:21Z"
Expected output: 2022-11-29T19:12:21.000+0000
I tried this script:
{
"lastDateTime": "2022-11-29T19:12:21Z" as DateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSS"}
}
Please help to get the expected output format.
A DateTime must have a timezone so you can not just parse the input string into it directly. The input also misses milliseconds so it can not be parsed with the milliseconds format .SSS.
You can convert to a LocalDateTime first, then add a timezone (+0:00), then format to string with milliseconds and timezone. A DateTime must have a timezone so you can not just parse the input
%dw 2.0
output application/json
---
{
"lastDateTime": ("2022-11-29T19:12:21Z" as LocalDateTime {format: "yyyy-MM-dd'T'HH:mm:ss'Z'"} ++ |+00:00|) as String {format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"}
}

How to convert string to date in pyspark

I have a file name from which I'm extracting date: some_file_name_20201103114823.csv using substring:
substring(input_file_name(),16,8)
I extracted date part, which is now string: 20201103
How can I convert this string to date in format: MM-dd-yyyy ?
This is what i did, formatted string and then cast it to date - not pretty but does the work:
to_date(concat(substring(input_file_name(),16,4),lit("-"),substring(input_file_name(),20,2),lit("-"),substring(input_file_name(),22,2)),"yyyy-MM-dd")
Reference: https://sparkbyexamples.com/pyspark/pyspark-substring-from-a-column/#:~:text=In%20PySpark%2C%20the%20substring(),using%20substring()%20from%20pyspark.

formatting date in mule 4 Dataweave

I am using now() to get current datetime in Dataweave, I would like to format it so special character are removed and I get plain format like this 20200723T1720334450200
Try
now() as String {"format": "yyyyMMdd'T'HHmmssSSSSSSS"}

not able to convert string date format in vb.net

I'm taking date from my csv file
Dim odateq As String = sData(0).Trim()
I am getting odateq as 9/15/2015
I want to convert this to 15/9/2015. So I wrote code like this
Dim newdate As DateTime = DateTime.ParseExact(odateq, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture)
And I'm getting an error like this :
String was not recognized as a valid DateTime.
any help is very appreciable...thanks
the code you wrote is using the wrong format; the date you have is in the format M/d/yyyy (month and day without leading zero are a guess because you did not specify it).
try with this one:
Dim newdate As DateTime = DateTime.ParseExact(odateq, "M/d/yyyy", System.Globalization.CultureInfo.CurrentCulture)
the format you set in the ParseExact was telling the function to expect a date in the format dd/MM/yyyy like 01/05/2015 but what you have is not in that format.
after you parse the input date, to get a string with format dd/MM/yyyy use:
Dim dateAsText As String = newdate.ToString("dd/MM/yyyy")

How translate string to date in .NET

I followed suggestion from vb.net convert string to date . But, it did not work.
the code is as follows:
Dim Dt As DateTime
If DateTime.TryParse("Thu, 09 Dec 2010 16:03:24 EST", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, Dt) Then
MessageBox.Show(Dt)
End If
Can anyone solve this for me? I need to have date populated in the format of "yyyy-mm-dd hh24-mi-ss".
this should get you on the right path:
Dim dt As DateTime
dt = Now
TextBox1.Text = Format(dt, "yyyy-MM-dd HH:mm:ss")
NOTE: this answer was written for a previous revision of the question which had the following code:
Dim Dt As DateTime
If DateTime.TryParseExact("Thu, 09 Dec 2010 16:03:24 EST", "dd.MM.yyyy", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, Dt) Then
MessageBox.Show(Dt)
End If
The format string that TryParseExact takes as it's second parameter specifies the format of the date in the string passed as the first.
In your case the format string is specifying that the date will be of the format "09.12.2010" for example - just the day, moth and year. However, as the string isn't in that format it won't parse. If you'd just used ParseExact it would have raised an exception.
The MSDN page for the variant of TryParseExact that takes an array of possible format strings has more examples, but non match your format exactly, but working with the format strings used to convert DateTime to string you probably want something like this:
"ddd, dd MMM yyyy HH:mm:ss ???"
but I can't find what you'd need instead of "???" to match the "time zone as string". You might have to do some string manipulation to remove this before calling TryParse or TryParseExact.
You will have to replace the timezone with the timezone offset.
Same question as Parse DateTime with time zone of form PST/CEST/UTC/etc
TextBox1.Text = System.DateTime.Now.AddMinutes(698).ToString("dd/MM/yyyy");
DateTime DOB;
string[] formatsDOB = { "dd/MM/yyyy", "MM/dd/yyyy" };
DateTime.TryParseExact(txtDateofBirth.Text, formatsDOB, CultureInfo.CurrentCulture, DateTimeStyles.None, out DOB);