Reading Time format data in spreadsheet using perl - perl

while reading the spreadsheet using perl, how the time format data (in a cell) in spreadsheet got read by perl ?
I tried to read text and numeric type data from a cell in worksheet, as a result, it got read as text and numeric in perl,
but while reading a time format data, it got converted to some float value(of format - HH:MM:SS/HH:MM/MM:SS), my doubt is that, how the time format ([H]:MM:SS) from a cell got read by perl ?
For example:
$cell holds the value of 13:7(is in time format [H]:MM:SS format in spreadsheet)
while reading it using perl,
$type = $cell->type() //returns the type : Numeric/Text
$format = $cell->get_format() // returns the format (i.e)if Numeric :returns time format of HH:MM:SS / HH:MM / MM:SS formats only
In such case, how data present in $cell can be read by perl? and how
other time formats such as MM:SS.0/[H]:MM:SS/YYYY-MM-DD HH:MM:SS/ [HH]:MM:SS...are identified?

In most cases (maybe all, but I've learned to be wary of statements like that), dates in Excel spreadsheets are stored as floating-point numbers where the integer part of the number is the number of days since the start of 1900 and the decimal part is how far through the day we are.
You can, of course, use that information to parse the data yourself. But there's no need to do that in a world where DateTime::Format::Excel exists.

Related

How do I convert Stata dates (%td format e.g. 30jan2015) into YYYYMMDD format (e.g. 20150130)

* date is in %td format
gen date1 = real(string(mofd(daily(date, "DMY")), "%tmCYN"))
* type mismatch error
tostring date, gen(dt)
gen date1 = real(string(mofd(daily(dt, "DMY")), "%tmCYN"))
* the code runs but generates no results
tostring date, gen(dt)
gen date2=date(dt, "YMD")
* the code runs but generates no results
If a date variable has a display format %td it must be numeric and stored as some kind of integer. The display format is, and is only, an instruction to Stata on how to display such integers. Confusions about conversion often seem to hinge on a misunderstanding about what format means, as format is an overloaded word in computing, referring variously to file format (as in graphics file format, .png or jpg or whatever); data layout (as in wide or long layout, structure or format); variable or storage type; and (here) display format. There could well be yet other meanings.
A date displayed as 30jan2015 is stored as an integer, namely
. display mdy(1, 30, 2015)
20118
and a glance at help data types shows that your variable date could be stored as an int, float, long or double. All would work, although int is least demanding of memory. You would need (e.g.) to run describe date to find out which type is being used in your case, but nothing to come in this answer depends on knowing that type. Note that finding out what Stata is doing and thinking can be illuminated by running display with simple, single examples.
Your question is ambiguous.
Want to change display format? If you wish merely to see your dates in a display format exemplified by 20150130 then consulting help datetime display formats shows that the display format is as tested here with display, which can be abbreviated all the way down to di
. di %tdCCYYNNDD 20118
20150130
so
format date %tdCCYYNNDD
is what you need. That instructs Stata to change the display format, but the numbers stored remain precisely as they were.
Want such dates as variables held as integers? If you want the dates to be held as integers like 20150130 then you could convert it to string using the display format above, and then to a real value. A minimal sandbox dataset shows this:
. clear
. set obs 1
Number of observations (_N) was 0, now 1.
. gen date = 20118
. gen wanted = real(strofreal(date, "%tdCCYYNNDD"))
. format wanted %8.0f
. l
+------------------+
| date wanted |
|------------------|
1. | 20118 20150130 |
+------------------+
A display format such as %8.0f is needed to see such values directly.
Another method is to generate a large integer directly. You need to be explicit about a suitable storage type and (as just mentioned) need to set an appropriate format, but it can be got to work:
. gen long also = 10000 * year(date) + 100 * month(date) + day(date)
. format also %8.0f
Want such dates as variables held as strings? This is the previous solution, but leave off the real(). The default display format will work fine.
. gen WANTED = strofreal(date, "%tdCCYYNNDD")
. l
+-----------------------------+
| date wanted WANTED |
|-----------------------------|
1. | 20118 20150130 20150130 |
+-----------------------------+
I have not used tostring here but as its original author I have no bias against it. The principles needed here are better illustrated using the underlying function strofreal(). The older name string() will still work.
Turning to your code,
tostring date, gen(dt)
will just put integers like 20118 in string form, so "20118", but there is no way that Stata can understand that alone to be a daily date. You could have run tostring with a format argument, which would have been equivalent to the code above. The advantage of tostring would only be if you had several such variables you wished to convert at once, as tostring would loop over such variables for you.
I can't follow why you thought that conversion to a monthly date or use of a monthly date display format was needed or helpful, as at best you'd lose the information on day of the month. Thus at best Stata can only map a monthly date back to the first day of that month, and at worst a monthly date (here 660) could not be understood as anything you want.
. di mofd(20118)
660
. di %td mofd(20118)
22oct1961
. di %td dofm(mofd(20118))
01jan2015
There is no shortcut to understanding how Stata thinks about dates that doesn't involve reading the needed parts of help datetime and help datetime display formats.
Yet more explanation and examples can be found at https://www.stata-journal.com/article.html?article=dm0067

In RPG, use a date, in *job format from a file

I'm trying to convert, in a RPG program, a date from a file (it's from the DSPJRN command, so the field si 6 numeric, in JOB format).
I want to use it as a date in my program, but I can't achieve it correctly.
I have tried to describe a field with type "D": date, keyword datfmt(*job) to convert the value from the file, but datfmt(*job) is incorrect (error RNF0612)
I have tried to retrieve the job Date format from a CLP program with RTVJOBA DATFMT(&FMT), and use the variable in RPG to convert the date like this
eval ztJODATE = %date(JODATE:FMT)
but it doesn't compile : error RNF0606 . I think that I can't use a variable for the format in the %date built-in function.
Is this a way to do what I want, or am I forced to transform the date value in SQL before using its value in RPG?
PS: I don't want to hardcode the format in my RPG program!
You can specify *JOBRUN for %DATE.
eval ztJODATE = %date(JODATE:*JOBRUN)
Note that RPG retrieves the job date format during initialization of the module, so if you change the job date format while the program is running, RPG will not understand the date.
Rather than using DSPJRN to an outfile, the recommended way to retrieve and process journal entries would be to use one of the programatic interfaces provided by IBM i.
Retrieve Journal Entries (QjoRetrieveJournalEntries) API
QSYS2.DISPLAY_JOURNAL() stored procedure
You could also use a *TYPE3 or higher format for the output file. Rather than the separate job formatted data & time fields, there's a single char(26) system timestamp field.
Having said that, there is a Convert Date and Time Format (QWCCVTDT) API that accepts '*JOB' as an input format specifier..

How to format input for SAS's MONYY format

I currently have a dataset with dates in the format "FY15 FEB". In attempting to format this variable for use with SAS's times and dates, I've done the following:
data temp;
set pre_temp;
yr = substr(fiscal,3,2);
month = substr(fiscal,6,length(fiscal));
mmmyy = month||yr;
input mmmyy MONYY5.;
datalines;
run;
So, I have the strings representing the year and corresponding month. However, running this code gives me the error "The informat $MONYY was not found or could not be loaded." Doing some background on this error tells me that it has something to do with passing the informat a value with the wrong type; what should I alter in order to get the correct output?
*Edit: I see on the SAS support page for formats that "MONYYw. expects a SAS date value as input;" given this, how do I go from strings to a different date format before this one?
When you see a $, it means character value. In this case, you're feeding SAS a character value and giving it a numeric format. SAS inserts the $ for you, but there is no such format in existence.
I'm going to ignore the datalines statement, because I'm not sure why it's there (though I do notice there is no set statement). You might have an easier time just changing your program to:
data temp;
yr = substr(fiscal,3,2);
month = substr(fiscal,6,length(fiscal));
pre_mmmyy = strip(month)||strip(yr);
mmmyy=input(pre_mmmyy,MONYY5.);
run;
you can also remove the "length(fiscal))" from the substring function. The 3rd argument to the substring function is optional, and will go to the end of the string by default.

Matlab and excel timestamp with datenum

At the moment I am using xlsread to open a set of data that I have in excel with given timestamps. But when these values are placed in matlab it changes the formatting of the timestamp.
In excel it is:
dd/mm/yyyy HH:MM
but when it puts it into matlab it changes it to
mm/dd/yyyy HH:MM
which ruins my other code. I have tried using formatIn and specifying it, but then it returns an error if no value for midnight is given.
Any help would be appreciated.
You can use datenum and datestr to convert the format to what you want. In the following example I'm assuming your timestamps are contained in a cell array of strings, but it also works if it's a char matrix:
>> timestamps = {'08/25/2014 13:14'; '08/26/2014 14:15'} %// mm/dd/yyyy HH:MM
>> result = datestr(datenum(timestamps, 'mm/dd/yyyy HH:MM'), 'dd/mm/yyyy HH:MM')
result =
25/08/2014 13:14
26/08/2014 14:15
What Luis recommended should help you to get any format that you like. However there is something important to realize here:
Excel does not 'have' the date in your format. It has the date stored as a number like 123546.123 and presents it to you in a certain way.
If you want to get the date in exactly the way that excel presents it, the trick is to avoid importing the relevant column as a date, but just import it as text instead.
How to do this depends on your import method, but it should not be very hard.

Date Comparsion not working in Access VBA

I am trying to compare two dates.
But the temp always returns true.
Can you explain where i am going wrong
temp = (Format(CDate("27-Aug-09"), "dd-mmm-yy") > Format(CDate("07-Jul-12"), "dd-mmm-yy"))
You're formatting the values according to dd-mmm-yy - which is actually the format they're in to start with. So you're just comparing the strings "27-Aug-09" and "07-Jul-12"... at which point "2" is later than "0", so the comparison finishes really quickly.
I suspect you can just get rid of the Format calls, to compare the dates:
temp = (CDate("27-Aug-09") > CDate("07-Jul-12"))
That's assuming that CDate can handle the input, of course. (I expect that part is fine.)
If you really want to compare strings, you need to convert the dates into a naturally sortable format, e.g. yyyy-mm-dd.