Posts: 1,058
Threads: 367
Joined: Oct 2007
I wonder whether there exists a simple way to convert a date string with month as its abbreviated name to that with the month as digits. I have written a short QM function which it converts properly, however I a looking for a relevant system resource. Let me mention that the statement :
DateTime(x).fromstr(s) gives an error, unless month is used in "s" with its representation in digits. Many thanks in advance.
Posts: 12,088
Threads: 142
Joined: Dec 2002
Probably not. I know only 1 API, and it is used in FromStr.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you. I attach my solution, for any interest.
Function
tempf03
function# str'mon
;_i=tempf03("Apr")
;out _i
lpstr m="JanFebMarAprMayJunJulAugSepOctNovDec"
int i=find(m mon)
if(i<0)
,err "Error in month"
i=i/3+1
ret i
Posts: 1,337
Threads: 61
Joined: Jul 2006
08-14-2018, 08:30 PM
(This post was last modified: 08-14-2018, 08:47 PM by Kevin.)
C# is your friend so easy to parse dates
i also had it output just the numeric month as another example
Using c# dont need to break the date apart can process it all together and customize output
Function
ParseDateExampleCs
_s.timeformat("{dd-MMM-yy}" 0)
out _s
str code=
;using System;
;using System.Globalization;
;public class Example
;{
;,,public static string StaticFunc(string date)
;,,{
;,,,,DateTime parsedDate = DateTime.Parse(date);
;,,,,Console.WriteLine(parsedDate.ToString("MM"));
,,,,;return parsedDate.ToString("dd/MM/yy");
;,,}
;}
str R=CsFunc(code _s)
out R
for more info see
Standard Date and Time Format Strings
Parsing Date and Time Strings in .NET
Custom Date and Time Format Strings