Error Converting DateTime using format - filehelpers

I get the following error when trying to import a CSV file.
Error Converting '2007/01/02' to type: 'DateTime'. Using the format: 'yyyy/MM/dd'
I have set the class like this:
[FieldConverter(ConverterKind.Date, "yyyy/MM/dd")]
public DateTime PriceDate;
Any idea why that could be, since the format matches - it is the second of Jan 2007?
When I change the date format to 2007.01.02 then Filehelpers parses perfectly.
I use V 3.1.5.0
Thanks

Try changing the mask to:
[FieldConverter(ConverterKind.Date, "yyyy/M/d")]
public DateTime PriceDate;
Click on the 'Converters' tab in this link to learn more about a handful of datatypes available, such as numeric and dates.

Related

Convert Integer to Date in Snowflake using Error Handling

I have a requirement where integer value should be converted to date type in Snowflake.Initially I used following query to get the desired result:
SELECT TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
2019-07-09
Now when I used same query for the input - "20200034", I am getting following error:
select TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
Can't parse '20200034' as date with format 'YYYYMMDD'
"20200034" is actually coming from one of the columns in snowflake table. To resolve this issue I tried using "TRY_TO_DATE" function, but output of "TRY_TO_DATE" function is giving incorrect result. Please find details below:
select TRY_TO_DATE(TO_varchar(19000000+1200034))
1970-08-22
As per Snowflake documentation, error handling function does not support optional format argument supported by TO_DATE , DATE.
https://docs.snowflake.com/en/sql-reference/functions/try_to_date.html
You can set the DATE_INPUT_FORMAT for the session before calling the TRY_TO_DATE function.
I suggest you contact Snowflake support and ask them to enable try_to_date with format string - it's available but needs to be enabled manually.
However you have to be aware that TRY_TO_DATE on '20200034' will be resolved to NULL.

Pentaho kettle convert date to unix

I'm trying to pacha a string format dated "2019-05-14 13:30:00" to a UNIX format.
In javascript I got it but in the javascript kettle module I am not able to return the numeric value 1557833442
the line of code is this:
const tests = (new Date ("2019-05-14 13:30:00"). getTime () / 1000);
It looks like the Date() constructor doesn't like the format you are using.
If you want the current date, use a Get System Info, it has a number of useful date options.
If you are converting an incoming field, use the Select Values step to change the metadata, using the format string that matches your string field's format.

Jqgrid Datetime format sorting issue

I have a datetime format returned from the backend(dd/MM/yyyy HH:mm:ss).
JQgrid has column values as {name:'createddate',index'createddate',sorttype:'date',formatter:'date'}
but the sorting is not working properly
the result is displayed as follows:for example
06/11/2013 01:23:33
11/09/2013 02:22:34
20/09/2013 01 22:33
but the result required is:
11/09/2013 02:22:34
20/09/2013 01:22:33
06/11/2013 01:23:33
Thanks in advance.
If you use formatter:'date' then you should specify formatoptions with srcformat and newformat options. Default format of input data (srcformat) which expect formatter:'date' is ISO8601Short: "Y-m-d". You use another format so you have to specify srcformat. Format of date which uses jqGrid is PHP format (described here). So I think that the problem will be solved by adding
formatoptions: {srcformat: "d/m/Y H:i:s", newformat: "d/m/Y H:i:s"}
More better would be to use ISO-8601 format if you returns data from the server. It's locale independent format. You can use on the server side DateTime.ToString("o") or DateTime.UtcNow.ToString("o"). In the case you can change formatoptions to
formatoptions: {srcformat: "ISO8601Long", newformat: "d/m/Y H:i:s"}

Getting view options in Microsoft Project using VBA

If I want to change the current date format to 20, for example, I can use the command
OptionsViewEx DateFormat:=20
but how can I get the current date format (or any other view option for that matter)?
DefaultDateFormat should be the function to use.
oldvalue = Application.DefaultDateFormat
Application.DefaultDateFormat = 20 ' or = pjDate_mm_dd_yyyy
This gets or sets the default date format. (technet)
This gives the complete list of format types.
If you use Date function get a date in current format, but if you need change use format(Date,"yyyy-mmmm-dd") for example.

SQL Server 2008 SSIS: Importing date field incorrectly (from Oracle)

The date fields in the file (CSV) I must import are in the format DD-MMM-YY, SQL Server is importing them as YY-MM-DD. So 01-FEB-13 is imported as 2001-02-13.
How can I change the format SQL uses to import the dates?
I don't have access to the original Oracle database, only the flat file exported from it. So everything I do pretty much has to be done in SQL.
Changing the date format that SQL Server uses by default would require mucking around with the Windows server culture settings. Not a good idea, especially if this is the only file where you're having this issue.
I would use a Script Transformation and the .NET Framework's DateTime.ParseExact method, which lets you completely control the expected format. Start by configuring the Flat File Connection Manager that you're using to read the CSV files so that the columns with the DD-MMM-YY dates have their DataType set to string or Unicode string rather than date, database date or any other date-specific type:
In your Data Flow, place a Script Transformation between your source and destination components, like thus:
Select each of the DD-MMM-YY date columns as inputs to the Script Transformation:
And create an output column with a DataType of date corresponding to each input column:
The Script Transformation code will look like this (using C#)
using System;
using System.Data;
using System.Globalization; // needed for CultureInfo.InvariantCulture
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void IncomingRows_ProcessInputRow(IncomingRowsBuffer Row)
{
string incomingFormat = "dd-MMM-yy";
Row.ConvertedCreateDate = DateTime.ParseExact(
Row.CreateDate,
incomingFormat,
CultureInfo.InvariantCulture);
Row.ConvertedLastUpdateDate = DateTime.ParseExact(
Row.LastUpdateDate,
incomingFormat,
CultureInfo.InvariantCulture);
}
}
You can use the to_char() function in oracle to format your dates so that they are in the format you want. Hopefully Gordon's comment about storing as text referred to a staging table. For a variety of reasons, your first import should be into a staging table anyway.