I think I have read just about every post on this topic and none of the proposed solutions works in my case so here goes.
I am using CF9 (upgrade not an option) for this project. I query a date field from a MSSQL database and use spreadsheetAddRows() to put the results into a spreadsheet (xls or xlsx, same result either way).
The date shows in excel as 2020-05-11 00:00:00.0 and isn't recognised as a date so the date formatting doesn't work.
I have tried using SpreadsheetFormatColumn (s, { dataformat="d-mmm-yy" }, 2); but this doesn't format the date either and has the exact same result in excel.
I have tried many variations of selecting convert(varchar, datecolumn, 101) from the database but these always just end up as text fields in excel as well so again, no date formatting and they sort in the wrong order.
Can anyone tell me what the correct format for a date is for CFSpreadsheet so that excel actually recognises it as a date?
Related
I have a column that has multiple comments along with some DateTime stamps. The example is like this:
abc#gmail.com - 03/03/2022 13:04:40
Documents Pending
Some random comment
I want to extract only the DateTime stamp from this column. I tried using to_char, and to_date functions in PostgreSQL, but none of it seems to work for me.
I also tried writing a regex to extract the DateTime stamp, but it didn't work.
What is the correct way to extract only DateTime from the above column? What would be the regular expression to extract the DateTime?
Thanks in advance.
Edit: I want to extract a date from a column like this:
abc#gmail.com - 12-Aug-2022
Documents Pending
Some random comment
How we can identify the month number or a date format from this comment?
You could use SUBSTRING() here:
SELECT col,
SUBSTRING(col FROM '\y\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\y') AS ts
FROM yourTable;
There is a large table containing among other fields the following:
ID, effective_date, Expiration_date.
expiration_date is datetime20. format, and can be NULL
I'm trying to extract rows that expire after Dec 31, 2014 or do not expire (NULL).
Adding the following where statement to the proc sql query gives me no results
where coalesce(datepart(expiration_date),input('31/Dec/2020',date11.))
> input('31/Dec/2014',date11.);
However, when I only select NULL expiration dates and add the following fields:
put(coalesce(datepart(expiration_date),input('31/Dec/2020',date11.)),date11.) as value,
put(input('31/Dec/2014',date11.),date11.) as threshold,
case when coalesce(datepart(expiration_date),input('31/Dec/2020',date11.)) > input('31/Dec/2014',date11.)
then 'pass' else 'fail' end as tag
It shows 'pass' under TAG and all the other fields are correct.
This is an effort to duplicate what I used in SQL Server
where isnull(expiration_date,'9999-12-31') > '2014-12-31'
Using SAS Enterprise Guide 7.1 and while trying to figure it out I've been using
proc sql inobs=100;`
What am I doing wrong ? Thank you.
Some Expiration Dates:
30OCT2015:00:00:00
30OCT2015:00:00:00
29OCT2015:00:00:00
30OCT2015:00:00:00
I would recommend using a date constant ("31DEC2014"d) rather than date functions, or else either use explicit passthrough or disable implicit passthrough. Date functions are challenging when going between databases and so avoiding them when possible is best.
I am exporting data from Dynamics CRM 2011 into an Excel File. The entries have timestamps. In CRM they look like normal dates, but when I export them into Excel the timestamps look similar to this:
41855.4043865741
41831.6309259259
In Excel I can right-click on the cell with the timestamp and do Cell Formatting > Numbers > Date and convert this to a human readable string.
e.g.
04.08.2014 09:42:19
11.07.2014 15:08:32
The problem is, after I save the Excel with the human readable Datetime format and read the Excel with the xlrd Module (Python 2.7) I still get the strange format and not the translated one.
So I tried using datetime Module to dranslate the date but when doing so I get the wrong date.
import datetime
str_dt = float(41831.6309259259)
print datetime.datetime.fromtimestamp(str_dt).strftime('%Y-%m-%d %H:%M:%S')
My result is: 1970-01-01 12:37:11
Of course it is not Unixtimestamp but I have no idea what timestamp it actually is and how I can convert it with python.
The values you see are the actual number of days since the 1st of January 1900. This is the format used by CRM and Excel.
As suggested in this answer, you can use xlrd.xldate.xldate_as_datetime to:
Convert an Excel date/time number into a datetime.datetime object.
#param xldate The Excel number
#param datemode 0: 1900-based, 1:
1904-based.
#return a datetime.datetime() object.
In your case the datemode would be 0.
guru, i am reading a big table with a column "issue_day" in "yy-mm" format. For example:
status issue_day
active 11-Dec
inactive 10-Dec
active 9-Dec
active 8-Jun
Is there any pythonic/pandas way to select data earlier than 2011? (For example, we only want data in 10-Dec & 09-Dec in this case). There is only "dayfirst" in the pandas to_csv command, but I don't see "yearfirst". Could any guru enlighten? Thank you
What about this?
df=pd.DataFrame(['11-Dec','10-Dec','09-Dec'],columns=['issue_day'])
df['issue_day']=pd.to_datetime(df['issue_day'],format="%y-%b")
print df[df['issue_day']<'2011']
Using CF10 Standard to create a spreadsheet from a query. No matter what I've tried so far, the formatting for a specific column stops at row 32 (1 header row, 31 data), even though the entire sheet is populated to 186 rows.
<cfscript>
dfStyle=StructNew();
dfStyle.fgcolor="pale_blue";
dfStyle.dataformat="mm/dd/yyyy";
theSheet = SpreadSheetNew('mysheet');
SpreadSheetAddRow(theSheet,'SID,FIRST,LAST,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,EMAIL,ADDED,PID');
SpreadSheetAddRows(theSheet,qry);
SpreadSheetFormatColumn(theSheet,dfStyle,10);
</cfscript>
I'm trying to get a consistent mm/dd/yyyy format on the 'ADDED' column. Instead, I'm getting that through row 31, and then getting dates like 41937.56594 on the of the rows.
In the formula bar I show "10/20/2014 12:25:23 PM" as the first value and "41932.552037037" as the 2nd value.
If I format the date in the query (i.e. date_format(sp_add,'%c/%e/%Y') AS spadd) I do get a nice date format all the way down the column, but the blue still stops at row 32.
Here is the cfoutput of the anonymized query - top row is formatted, bottom row loses formatting (background color - formatting dates in query). I also dropped the ADDRESS2 column from the query for now.
I'm not sure what the problem is, but try using the XML format option (the option to produce an xlsx file instead of the older style xls file). In your code add the "true" as a second argument to your spreadsheetnew() function call.
<cfscript>
dfStyle=StructNew();
dfStyle.fgcolor="pale_blue";
dfStyle.dataformat="mm/dd/yyyy";
theSheet = SpreadSheetNew('mysheet',TRUE);
SpreadSheetAddRow(theSheet,'SID,FIRST,LAST,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,EMAIL,ADDED,PID');
SpreadSheetAddRows(theSheet,qry);
SpreadSheetFormatColumn(theSheet,dfStyle,10);
</cfscript>
This will solve the problem - though we don't know why :)