I'm trying to use powershell to convert a string that contains RFC 2822 formatted dates into another format. Right now I'm getting an error saying my string was not recognized as a valid DateTime.
Write-Host ([Datetime]::ParseExact('Thu Oct 07 09:23:26 UTC 2021', '[R][1]', $null)).ToString("yyyyMMdd")
I'm not sure what I'm doing wrong.
The R standard datetime format string specifier does not describe the format you've supplied.
You're gonna need a custom format string:
[Datetime]::ParseExact('Thu Oct 07 09:23:26 UTC 2021', 'ddd MMM dd HH:mm:ss UTC yyyy', $null)
Related
I'm trying to implement a PowerShell script to compare DateTime from certificate file(Jave Keystore).
However, the DateTime format that I extract from keystore file is quite complex as example below.
Mon Mar 13 06:40:26 CDT 2023
Sat Sep 18 20:41:47 CDT 2027
It includes time and timezone in the String but I actually need only date like 13-Mar-2023.
Could anyone help suggest how I return this String to be DateTime for comparison?
Thanks a lot.
You can use the [datetime]::ParseExact() method for this:
$dateString = 'Mon Mar 13 06:40:26 CDT 2023'
$date = [datetime]::ParseExact($dateString, 'ddd MMM dd HH:mm:ss CDT yyyy', [cultureinfo]'en-US')
$date.ToString('dd-MMM-yyyy')
Result:
13-Mar-2023
CDT means Central Time Zone (UTC - 6), switched to DayLight Saving Time --> Central Daylight Time (CDT) which is five hours behind UTC
According to the documentation, it seems that it is only possible to manipulate dates with a numeric format, and not letters.
Does a package exist if I want to display date with the format Thur, Aug 23 ?
If not, how could I do this ?
Thank you !
You can create your own DateFormat using it's default constructor.
The format you want is EEEE, MMM d.
For Example print(new DateFormat("EEEE, MMM d").format(new DateTime.now())); should print Wedn, Jun 26 for today.
I am trying to copy data from Excel to a SQL table.
I have dates generated in Excel file using RAND function. I am taking them as strings in an input and trying to convert them in date data type using tConvertType.
I have setted its datatype as 'string' in initial input and as 'date' in tConvertType's output and in tMSSqlOutput.
My job has work flow Excel input -> tConvertType -> tMap -> tMSSqlOutput.
While running the job I am getting an error which says :
java.text.ParseException: Unparseable date: "Tue Jul 17 00:00:00 EDT 1973"
I am not sure where the problem lies.
If anyone could help me with this it would be much appreciated.
Here's the screenshot of my job.
i am able to parse your given sample date please use below function in tMap for your date filed.
System.out.println(TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss zzz yyyy", 'Tue Jul 17 00:00:00 EDT 1973', "EN"));
function is yourDateColumn!=null && !"".equalsIgnoreCase(yourDateColumn)? TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss zzz yyyy", yourDateColumn, "EN") :null
#UmeshR: your code is working fine, but you have to handle the timezone thing as well. e.g. I am from India and when i converted the time from EDT talend converted it to my local timezone. see the screen-shot.
I have a question regarding date formatting in Lua (Luajit). I need to get UTC string, for example, like I would do it in JavaScript:
var date = new Date()
console.log(date.toUTCString()) // "Fri, 06 Dec 2013 14:05:28 GMT"
Unfortunately in Lua I cannot find possibility to format date this way:
print(os.date()) -- Fri Dec 6 16:06:43 2013
From the Lua manual:
If format starts with '!', then the date is formatted in Coordinated Universal Time. [...]
If format is not "*t", then date returns the date as a string, formatted according to the same rules as the ANSI C function strftime.
Based on this and a little documentation referencing, it's quite simple to construct a format string that resembles JavaScript's toUTCString format.
> =os.date('!%a, %d %b %Y %H:%M:%S GMT')
Fri, 06 Dec 2013 14:27:34 GMT
I am creating an app which is using RSS feed.
in that I have to parse a dateTime string.
string coming in data is : Tue, 17 Sep 2013T04:00:00 GMT
I can not convert it into date because of that T b/w year and hour.
Can anyone please provide me the date format for this?
I am using formate like EEE, dd MMM yyyy HH:mm:ss ZZZ
But it is giving null value
I used : EEE, dd MMM yyyy'T'HH:mm:ss ZZZ
and it worked..