i have been trying to convert a string to date using
${test:toString():toDate('dd-MMM-yy HH.mm.ss.SSSSSSSSS'):format('dd-MMM-yy HH.mm.ss.SSSSSSSSS')}
my value for test attribute is like 13-MAR-20 15.50.41.396000000
when i'm using the above mentioned expression to convert the string to Date, it actually is changing the date as below:
test (input value):
13-MAR-20 15.50.41.396000000
time (output value)
18-Mar-20 05.50.41.000000000
please advise!
I ran into a similar issue with date time encoded in ISO 8601.
The problem is, that the digits after the second are defined as fragment of a second, not milliseconds. If it has 3 digits, it equivalent to milliseconds. If more than 3, the toDate() function parse the fragment of a second as milliseconds. In your case 396000000 milliseconds = 4,58333333 days.
I solved my issue with replaceAll() by cutting digits to first 3.
${test:replaceAll('(\.[0-9]{3})([0-9]+)','$1')}
But my value was formatted as 18-06-20T05:50:41.396000000, so maybe you have to adjust the regex.
Related
I am receving the date in xsd:dateTime format "2021-10-20T15:30:46Z" and I want to convert the same to "2021-10-20T15:30:46.000+04:00" in xslt 2.0.
I am not able to get the right picture string.
format-dateTime($DateTime, "[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001]Z")
but it is returning "2021-10-20T15:30:46Z"
This is not a problem of formatting. In order to get the result you want, you need to (a) subtract 4 hours from the given dateTime and (2) adjust the result to a timezone with offset of 4 hours:
adjust-dateTime-to-timezone(xs:dateTime($DateTime) - xs:dayTimeDuration('PT4H'), xs:dayTimeDuration('PT4H'))
I'm currently using the following formula:
=IFS(regexmatch(A2,"Malaysia"),
B2-dataset!B3,REGEXMATCH(A2,"Saudi Arabia"),
B2-dataset!B7,REGEXMATCH(A2,"Taiwan"),
B2-dataset!B11,REGEXMATCH(A2,"Russia"),
B2-dataset!B15,REGEXMATCH(A2,"Greece"),
B2-dataset!B19,REGEXMATCH(A2,"South Africa"),
B2-dataset!B23,REGEXMATCH(A2,"UAE"),
B2-dataset!B27,REGEXMATCH(A2,"Albania"),
B2-dataset!B31,REGEXMATCH(A2,"India"),
B2-dataset!B35,REGEXMATCH(A2,"South Korea"),
B2-dataset!B39,REGEXMATCH(A2,"Turkey"),
B2-dataset!B43)
The idea is that B2 (currently as =date(dd/mm/yyyy) has a deadline date. C2 (in which the formula houses) should show the date when everything should be delivered.
Currently the outcome is a number, not a date. I've tried IF statement, which delivers a date but I can only add 3 arguments. Can someone help me?
Kind regards
if your current output is number like 40000+ it's ok and it's just formatting issue. either you will format it internally or use a formula.
try:
=TEXT(IFS(regexmatch(A2,"Malaysia"),
B2-dataset!B3,REGEXMATCH(A2,"Saudi Arabia"),
B2-dataset!B7,REGEXMATCH(A2,"Taiwan"),
B2-dataset!B11,REGEXMATCH(A2,"Russia"),
B2-dataset!B15,REGEXMATCH(A2,"Greece"),
B2-dataset!B19,REGEXMATCH(A2,"South Africa"),
B2-dataset!B23,REGEXMATCH(A2,"UAE"),
B2-dataset!B27,REGEXMATCH(A2,"Albania"),
B2-dataset!B31,REGEXMATCH(A2,"India"),
B2-dataset!B35,REGEXMATCH(A2,"South Korea"),
B2-dataset!B39,REGEXMATCH(A2,"Turkey"),
B2-dataset!B43), "dd/mm/yyyy")
I'm writing an application with Flutter. I read the times and dates from a source. The date and time format string sent by the resource is:
(Day, Month, Year, Hour, Minute, Second)
07.04.2021 13:30:00
03.04.2021 11:30:00
04.04.2021 17:30:00
03.04.2021 17:30:00
I want to convert this date and time format to DateTime data type with DateTime.parse() function. Here are some examples of what this function accepts as strings and what I need:
"2012-02-27 13:27:00"
"20120227 13:27:00"
"20120227T132700"
I have to convert the string type data coming to me from the source into one of these formats. But in Dart language I couldn't create the Regular Expression needed to do this and couldn't find it anywhere.
I would be very grateful if anyeone could help me understand what I should do.
If you have to play a lot with the dates, you could use the Jiffy package to ease your development.
DateTime yourDatetime = Jiffy("07.04.2021 13:30:00", "dd.MM.yyyy hh:mm:ss").dateTime;
This is a piece a cake by using regular expressions:
var regExp = RegExp(r'(\d{4}-?\d\d-?\d\d(\s|T)\d\d:?\d\d:?\d\d)');
use DateFormat.parse and DateFormat.format from intl package:
https://api.flutter.dev/flutter/intl/DateFormat/parse.html
https://api.flutter.dev/flutter/intl/DateFormat/format.html
final date = DateFormat("yyyy.MM.dd HH:mm:ss").parse("07.04.2021 13:30:00");
DateFormat("yyyy-MM-dd HH:mm:ss").format(date);
DateTime.parse accepts only a subset of ISO 8601 formats: https://api.flutter.dev/flutter/dart-core/DateTime/parse.html
I have a google sheet script that fetches youtube's video durations. The problem is the time data is in the ISO 8601 format.
For example:
PT3M23S
The formula I'm using right now does a good job converting this into a more readable format.
=iferror(REGEXREPLACE(getYoutubeTime(B20),"(PT)(\d+)M(\d+)S","$2:$3"))
It converts the above into a more readable format 3:23
Now the issue at hand is if the duration of the video is exactly 3 minutes or if the video is shorter than 1 minute regexreplace doesn't reformat it.
Instead it reads
PT4M OR PT53S
Is there a way to edit the formula to address each variant that potential could occur?
Where it would format PT4M into 4:00 or PT53S into 0:53
Lastly, if the seconds in the duration are between 1-9 the API returns a single digit value for the seconds. Which means the formula above will look wrong. For example, PT1M1S is formatted into 1:1 when it should read 1:01
It would be great if the formula could account for the first 9 seconds and add a 0 to make it more readable.
Thanks for reading this far, if anyone could help me out I'd very much appreciate it.
Just in case its easier to do this within the script itself here's the custom script that retrieves the video duration.
function getYoutubeTime(videoId){
var url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + videoId;
url = url + "&key=";
var videoListResponse = UrlFetchApp.fetch(url);
var json = JSON.parse(videoListResponse.getContentText());
return json["items"][0]["contentDetails"]["duration"];
}
Is very ugly, but seems to work for the examples provided:
=iferror(left(mid(A1,3,len(A1)-2),find("M",mid(A1,3,len(A1)-2))-1)*60,0)+substitute(REGEXreplace(mid(A1,3,len(A1)-2),"(.+M)",""),"S","")
Outputs seconds, eg 203 from PT3M23S. To change to 00:03:23 wap the above formula in ( ... )/86400 and format result as Time.
Script Solution:
function iso8601HMparse(str) {
return str.replace(/PT(\d+(?=M))?M?(\d+(?=S))?S?/g,function(mm,p1,p2){//regex to get M and S value
return [0,p1,p2].map(function(e){
e = e ? e:0;
return ("00"+e).substr(-2); //fix them to 2 chars
}).join(':');
})
}
Splice it in your script like:
return iso8601HMparse(json["items"][0]["contentDetails"]["duration"].toString());
Spreadsheet Function:
=TEXT(1*REGEXREPLACE(REGEXREPLACE(A1,"PT(\d+M)?(\d+?S)?","00:00$1:00$2"),"[MS]",),"MM:SS")
Late to the party, but here's what I'm using:
=TIMEVALUE(
IFERROR(TEXT(MID(A1,3,FIND("H",A1)-3),"00"),"00")&":"&
IFERROR(TEXT(MID(A1,IFERROR(FIND("H",A1)+1,3),FIND("M",A1)-IFERROR(FIND("H",A1)+1,3)),"00"),"00")&":"&
IFERROR(TEXT(MID(A1,IFERROR(FIND("M",A1)+1,3),FIND("S",A1)-IFERROR(FIND("M",A1)+1,3)),"00"),"00"))
You can also stick ARRAYFORMULA in front of this and change A1 to a a column to get values for a whole list of them.
I have some code that reads a datetime from a sqlite database, the datetime is returned as a string. when I try to convert it to a date using QDateTime::FromString it returns an invalid date. Below is the time as returned from the database and conversion.
Why is this failing to parse?
// -this is the value returned from the DB currentServerTime=2012-01-17 19:20:27.0
QString format("yyyy/MM/dd hh:mm:ss");
QString qCurrentServerTime(currentServerTime);
now = QDateTime::fromString(qCurrentServerTime, format);
No expert in QT, but if QDateTime::fromString() works as one would (reasonably) expect and according to this, you're not using the correct pattern.
You indicate the string read from the sqllite database is like "2012-01-17 19:20:27.0", then your format should be like yyyy-MM-dd HH:mm:ss.z.
In detail:
Your separator should by '-' not '/' (as you show in the example)
The time seems to be in 24 hours format (19 -> 7 p.m.) (so use HH instead of hh)
You have one digit for milliseconds, so add .z.