Two datetime formatting strings in one vector - datetime

i have a large structure dataset.
each field in the structure is a XXXX*4 cell. the XXXX are because they are not constant in size. the first column is datetime.
the problem is that part of the vector is in the format of: '1/9/2015 00:00:00' that is dd/MM/yyyy HH:mm:ss
while the other part is in the format of '1/9/2015 00:00' that is dd/MM/yyyy HH:mm.
this change can happen more then once in each date vector.
is there any way to call the datetime function with two format types? or a general one that covers both of these?
for lack of a better option i would scan each row, and fix it, but it would take a lot of time. hope someone can help... thanks.

well, i just made a for loop, and wrote this inside:
s=fieldnames(DataSet);
for i=1:length(fieldnames(DataSet))
for j=2:(length(DataSet.(s{i})))
if length(DataSet.(s{i}){j,1})>=17
DataSet.(s{i}){j,1}=DataSet.(s{i}){j,1}(1:(length(DataSet.(s{i}){j,1})-3));
end
end
end
it worked. actually pretty fast, only took 7 seconds (i was a bit surprised)
notice it only works to change from 'dd/MM/yyyy HH:mm:ss' to 'dd/MM/yyyy HH:mm'.
but i guess you can manipulate it to adjust most types.

Related

How to convert character type date to date type in SAS

I have a character variable in the form of "Jan-17" in my table and would like to convert it to date type. Does anyone what kind of date form this is and how I could go about converting it? Thank you.
SAS date variables are stored as number of days since Jan 1, 1960. For a variable that is Month and Year only, you'd need to pick a day - many choose the 1st, some the 15th or 30th/31st, depending on your business rules.
Either way, you can use the input function as a starting place. You need to know the informat - the instructions for how to translate characters to numbers. In your case, MONYY6. will likely work, though you can also try ANYDATEDTE. to let SAS guess the date informat to use.
Then, if needed, you can adjust the date it chose based on your business rules using the intnx function, which allows you to adjust it to the 15th or end of month if you prefer.
Use the INPUT() function with the correct informat.
data have;
date_char = 'Jan-17';
run;
data want;
set have;
date_dt = input(date_char, monyy6.);
format date_dt date9.;
run;
01JAN2017

Return wrong date in moment js with full format "DD-MM-YYYYTHH:mm:SSZ"?

I'm using momentjs to convert String to date in with full value of date and time and the result always increases about 12 hours. just like the picture below.
So how come does it go like this and how I can do to solve the problem. Many thanks.
"Z" at the end indicates that the date is provided with UTC-0 zone. momentjs internally shifts the timezone to suit your own. You should omit it if you want to reformat provided datetime string.

IF with duration (hh:mm:ss)

I have a column of durations that I received in text format looking like 00:01:20s. I removed the s from the end and formatted it as duration in Google Sheets, so the text 00:01:20 became duration 00:01:20.
What I'd like to do is take each entry that is 0:00:00 and change it to 0:00:01. Here's my formula (where column B contains the duration):
=if(B2=00:00:00,00:00:01,B2)
When I run it, I get Formula parse error.
I double-checked to make sure that column B was usable in calculations by adding two cells, and the result was correct. The column in which I put the formula is also formatted as duration. I've been Googling, and somehow haven't found another case of this error.
What am I missing?
I avoid Duration format (at least for the time being!) but please try:
=if(VALUE(B2)=0,time(0,0,1),B2)

Incrementing date column in sqlite3

I have a sqlite3 table with dates stored as text not null with the format MM-DD-YY, and have been doing most of my manipulation in Java by iterating through the cursor, however, it's proving to be a bit ugly/cumbersome, and I was wondering if there's any way to do an update statement in sqlite3 to increment/decrement all records by a certain number of days. I'm mostly having trouble figuring out how to convert my text column into a format that I can use with something along the lines of datetime(myDate, '+1 Day');. Can anybody point me in the right direction? Thanks guys!!
The documentation of the built-in date functions documents the supported date format:
YYYY-MM-DD
You should store your date values in this format.
If you cannot do this, you can use substr() to extract the fields of the date and convert it into the supported format.

Does this time format look familiar?

Can someone help me tell what datetime format is this, or what are it's parts?
e.g.
201106020539Z0000031552001001
201106020702Z0000000000001
201105140701Z0000000000001
201105170207A0000018560001001
I think I've got the first few parts (201106020539 is yyyymmddhhmm), but from the Z / A character onward, I have no clue. Is it possible that the rest isn't a datetime at all?
The Z implies Zulu or UTC time https://meta.stackexchange.com/questions/14684/so-html-formats-time-incorrectly, as for what comes after, I don't know since all other time data has already been indicated prior to the Timezone Character.
Also, the fact that your timestamps don't seem to end in the same number of characters suggests they might not be the same format/spec? Where did you obtain them?
In which context did you get these strings? I would guess that the digits are the seconds fractions.
Maybe this helps you:
For a UTC time (a DateTime.Kind
property value of DateTimeKind.Utc),
the result string includes a "Z"
character to represent a UTC date.

Resources