Rearranging the content of a cell in Cognos 10 - cognos

I've got birthdays as a varchar formatted as dd-mm-yyyy and I'm trying to build a filter that shows only the birthdates of the last 7 days.
Now normally I'd convert that field to a date field, but since it contains dummy values this isn't an option.
So I want to change the output to YYYYMMDD so I can use the value in a => filter.
How can I do this?

If you want the result in string format:
substring([Date],7) || substring([Date],4,2) || substring([Date],1,2)
..or in integer format:
cast(substring([Date],7),integer) * 10000 + cast(substring([Date],4,2),integer) * 100 + cast(substring([Date],1,2),integer)

Related

Converting xx:xx:xx time formation to minutues in Excel

I'm currently working on a dataset that has a duration field in time format, I'm trying to convert this into just minutues however haven't been succesful in doing so.
Is there a formula to convert these formats into mintues or seconds.
The format is HH:MM:SS some examples of data displayed and required output below.
Example
00:01:00 = 1
00:01:30 = 1.5
00:02:00 = 2
It depends on whether Excel sees these as DateTime or Text. To know this you can put =ISNUMBER( cell address ). If true, then it is DateTime. You can do =ISTEXT( cell address ) to see if it is text.
If it is DateTime, you can use this to convert it to minutes:
= A1 * 24 * 60
to convert it to minutes (where A1 is the cell with the 00:xx:xx value).
If text, then you need to do:
=TIMEVALUE(A1)*24*60
And even if it is already datetime, you can use =TIMEVALUE( cell address )*24*60 - it will figure out if it is text or already datetime.

separating date and time from datetime column in excel

how to separate date and time from datetime column if you have the format as below :
click here to view image
I am trying int(datetime column) for fetching date ; Datetime column - int(datetime column) for fetching time column
Your formula cannot work because your data is a text string (note that it has a letter included) and not a number.
So first convert the string into a "real" time with:
=substitute(a2,"T"," ")
You can then use:
Date: =INT(SUBSTITUTE(A2,"T"," "))
Time: =MOD(SUBSTITUTE(A2,"T"," "),1)
and be sure to format the results as desired:
If your column is formatted true date then use to separate date
=TEXT(A1,"yyyy-mm-dd")
For time
=TEXT(A1,"hh:mm:ss")
If data is in text string or output by TEXT() function then try below functions.
for date =TEXT(FILTERXML("<t><s>"&SUBSTITUTE(A1,"T","</s><s>")&"</s></t>","//s[1]"),"yyyy-mm-dd")
for time =TEXT(FILTERXML("<t><s>"&SUBSTITUTE(A1,"T","</s><s>")&"</s></t>","//s[last()]"),"hh:mm:ss")
For date
=LEFT(A2,FIND("T",A2)-1)
For time
=RIGHT(A2,LEN(A2)-FIND("T",A2))

Date export from Matlab to excel

i have a set of data for couple of days and the names of the data files like this
name='Newyork20200915'
which is for the 15th of September and i want to export only the date to excel like shown below
So how can i get the date from the name string ?
Thanks in advance
Assuming that the other part of name will not contain any digits besides the date, you can use regexp to get all the digits from the character array:
name = 'Newyork20200915'
date_only = regexp(name, '\d*', 'match')
Next, you can convert this date string to a serial date number using datenum, by providing the format in which the date is currently. And then use datestr to format it to your desired format.
date_formatted = datestr(datenum(date_only, 'yyyymmdd'), 'dd. mmm')
date_formatted =
'15. Sep'

SAS: Date reading issue

I have imported an excel sheet where the date1 is 4/1/16 date2 is 5/29/14 and date3 is 5/2/14. However, when I import the sheet into SAS and do PROC PRINT gives the first 2 variable columns as "42461" and "41788" while the date3 is 05/02/2014.
I need these date formats consistent b/c I am doing a Cox regression with PROC PHREG.
Any thoughts about how to make these dates consistent?
Thanks!
This probably depends on how the data is represented in Excel and how it is imported into SAS. First, are the formats the same in Excel? The first two are being imported as a number. The second as a string.
In Excel, you can format the column using a date format. Perhaps your import method will recognize this. You can also define another column as a string, using the text(<whatever>, "YYYY-MM-DD") to convert to a string in that format.
Alternatively, you can import all as numbers and then add the value to 1899-12-31. That is the base date for Excel. This makes more sense if you think of "1" as being 1900-01-01.
Because your column had mixed numeric (date) and character values SAS imported the field as character. So the actual dates got imported as the text version of the actual number that Excel stores for dates. The ones that look like date strings in SAS are the fields that were strings in Excel also.
Or if in your case one of the three columns was all valid dates then SAS imported it as a number and assigned a date format to it so there is nothing to fix for that column.
The best way to fix it is to make sure that all of the values in the date column are either real dates or empty cells. Then PROC IMPORT will be able to make the right guess at how to import it.
Once you have the strings in SAS and you want to try to fix them then you need to decide which strings look like integers and which should be treated as date strings.
So you might just check if they have any non-digit characters and assume those are the ones that are date strings instead of numbers. For the ones that look like integers just adjust the number to account for the fact that Excel numbers dates from 1900 and SAS numbers them from 1960.
data want ;
set have ;
if missing(exel_string) then date=.;
else if notdigit(trim(excel_string)) then date=input(excel_string,anydtdte32.);
else date=input(excel_string,32.) + '01JAN1900'd -2 ;
format date yymmdd10. ;
run;
You might wonder why the minus 2? It is because Excel starts from 1 instead of 0 and also because Excel thinks 1900 was a leap year. Here are the Excel date numbers for some key dates and a little SAS program to convert them. Try it.
data excel_dates;
input datestr :$10. excel_num :comma32. #1 sas_num :yymmdd10. ;
diff = sas_num - excel_num ;
format _numeric_ comma14. ;
sasdate1 = excel_num - 21916;
sasdate2 = excel_num + '01JAN1900'd -2 ;
format sasdate: yymmdd10.;
cards;
1900-01-01 1
1900-02-28 59
1900-03-01 61
1960-01-01 21,916
2018-01-01 43,101
;

Convert milliseconds to date (in Excel)

I have a row in excel with the following data: 1271664970687 (I think it's the number of milliseconds from 1970...).
I would like to have addition row that will show it as date/time.
Converting your value in milliseconds to days is simply (MsValue / 86,400,000)
We can get 1/1/1970 as numeric value by DATE(1970,1,1)
= (MsValueCellReference / 86400000) + DATE(1970,1,1)
Using your value of 1271664970687 and formatting it as dd/mm/yyyy hh:mm:ss gives me a date and time of 19/04/2010 08:16:11
See Converting unix timestamp to excel date-time forum thread.

Resources