I am using OpenXML in C# for creating xlsx file but date comes as Jan 1900 - openxml

In C# I am using OpenXML document format spreadsheet to create xlsx file. but excel gets created with date 'Jan 1900'. I am applying stylesheet document to spreadsheet document. Please help to get exact date.
I expects date should be 01/01/2019 which comes from datatable but actual output is Jan 1900

I think one of the solutions is to use the TEXT function.
Let's say you have a variable contains the date named dDate.
Then, put this in the cell where you want the value to be displayed:
=text(dDate,"mm/dd/yyyy")
Maybe you need to use C# grammar to do the concatenation of the string and the variable.

Related

MS Access: importing Date "3 Dec 2020" into 'date/time' column gives error, how do I get it to recognise it's a date?

I'm very, very new to databases, and trying to collect data from online shops we use. Apologies if this is a repeat question, I couldn't find existing questions that matched my problem for the life of me.
One of the sites we use gives dates in the format "3 Dec 2020" when I download a .csv file.
If I try to import into a table whose 'Date' column is formatted "Date/Time", it throws an error and won't log the date information at all.
If I import the .csv data when the Access 'Date' column is formatted as a "Short Text" column, and then after it's imported, change it back to "Date" format, it's fine and reformats those dates to 3/12/2020 format.
Putting in a space (" "), or "-", as the date delimiter when looking at the advanced import specification doesn't seem to work to get it to log the dates in a column formatted "Date/Time"
I tried looking into Masks but was quite confused by it
Could someone help me figure out how to get it directly into a 'Date/Time' column instead of me having to set it as 'short text' and back to 'date/time' again?
Thanks ><
Don't import the file but link it.
Then, use the linked table as source in a simple select query where you modify and filter the data as needed. For example, both CDate and DateValue will convert a text date to a true DateTime value:
TextDate = "3 Dec 2020"
TrueDate = DateValue(TextDate)
' TrueDate -> 2020-12-03
Finally, run an append query using the select query as source to append the data to your table.

Date format issue while uploading and saving the excel sheet into db using coldfusion cfspreadsheet

I uploaded and parsed through an excel sheet using cfspreadsheet and inserted all the values into database and the problem is that [my excel sheet has a date range from 1/2/2016 to 29/02/2016,from 1/2/16 to 12/2/2016 it is right aligned in excelsheet and remaining is left aligned...]. The value is being inserted into the db but I cannot able to fetch the values from 1-12 using where condition in db. I tried manually changing the date format in my excel sheet..what happened is
..02 January 2016
02 February 2016
.
.
02 December 2016
13/02/2016
14/02/2016
.
.
up to 02/12/2016[mm/dd/yy] it is displaying dd as month notation and from 13/02/2016[dd/mm/yyy] it is displaying properly, I tried with all formatting options, and I need to implement it in code. I think while downloading the data itself the date is not getting formatted properly, I tried with different excel sheet but of no use...and I tried converting these dates into specific format using coldfusion code and but it doesn't works for me..
<cfset sheet = spreadSheetRead("D:\file123\final1231.xls")>
<cfset SpreadSheetFormatColumn(sheet,{dataFormat="yyyy-mm-dd"},3)>
<cfset SpreadSheetWrite(sheet,"D:\file123\final1232",true)>
can any one help me in this?
What looks to me is that locale is set to 'English (United States)' in your excel and that is why for first 12 rows your excel is treating values as valid date but starting 13th row the data is invalid and hence excel is treating it as string (hence left aligned). Try manually changing excel locale to 'English (India)' or similar and you will see data aligned properly.
Also Cold Fusion internal date-time format is American (mm/dd/yyyy) and by default will interpret date and time into American format. I think while inserting data you can create date with something like below to make sure what data gets inserted:
#createDate(listLast(dt,"/"),listFirst(listRest(dt,"/"),"/"),listFirst(dt,"/"))#
Here dt is the data column that you want to insert. You may need to put some checks, based on the data, to avoid any run time errors.

Excel writer date format error

I have a source data(.csv) with a Date column which a format
"dd/mm/yyyy" and when I try to output this date column into Excel writer, it gives me an error and also Excel writer step doesn't has the same format built-in in the content tab-->fields-->Type of this step. I even tried using select values step and specified the metadata of date format as "dd/mm/yyyy".
Transformation:
Drop-down date format list from Microsoft Excel Writer step:
Microsoft Excel Writer does support Date type with dd/MM/yyyy format which is properly saved in a cell within a created file. I suggest you don't choose the option from drop-down, as it may not be full, but rather type it by hand.
Here's an example I've run which proves it:
As an additional note it's good to remember, that if you ever face such issues and find that even though you can ensure formatting of a column in previous steps in the step where it can't be enforced you could go for String type with # format - this would treat the input column value as-is and thus not altering it in any way that it came from the previous step.

PHPExcel expects date format d/m/y, but m/d/y entered. How to set PHPExcel Reader object to use custom date format for conversions

I need to read an excel spreadsheet with date format m/d/y into database. However, PHPExcel is outputting the wrong date because it thinks the date format is d/m/y.
How can I tell PHPExcel reader object to use the format m/d/y?
If the date is simply a string in the excel file, then you can use the standard PHP functions for string to date conversion (either strtotime() or DateTime objects). If the date is stored as an Excel timestamp, then you can use the PHPExcel built-in functions (PHPExcel_Shared_Date::ExcelToPHP() or PHPExcel_Shared_Date::ExcelToPHPObject()) to convert from the Excel timestamp value to a PHP/Unix timestamp or DateTime object, and then use the standard PHP date functions or DateTime methods to format it however you wish.
For clarity if other people encounter this problem:
Spreadsheet contains date 02/04/2014
You/Client/Boss entered date to be: m/d/y or February 4th, 2014
PHPExcel sees it as: d/m/y or April 2nd, 2014
The solution is to avoid the situation altogether by using the correct date formatting when the spreadsheet is created or use general formatting instead.
Q) What do I do if my client provided the spreadsheet to me?
A) Search for an entire day for a solution until you come to the same conclusion as I did or you can save yourself time and ask the client to send you another spreadsheet with the correct formatting.

CSV date Format issue

When I am using date in a .csv file it creats a problem as like I have used 01/01/2011 it takes 1st jan 2011,that's right but when I use 01/10/2011 it takes it as 10th jan 2011. I mean to say it always takes in mm-dd-yyyy format. I have some gb of files are there to be converted into csv. When I am converting these files dates in the files are in dd-mm-yyyy format. And after conversion the value changes completely.Hence How to resolve this issue? Hope I made my requirement clear.
Try the following:
DateTime.ParseExact("01/10/2011","dd/mm/yyyy",CultureInfo.CurrentCulture);
This specifies the format of the date in the string and should convert your dates correctly.