I tried to use
sqlDr.GetValue(a).ToString()
to display a DATE column from my database which looks like this..(the Date Submitted column)
But the problem is , when i display it using getValue(8).toString(), something like this is displayed..
Thanks for taking your time to read my post , any reply is much appreciated!
The problem is .Net does not have a Date-only primitive type. Therefore the Sql Server Date column type maps to a full DateTime value in .Net, which always includes a time component. If you don't provide a time component, the DateTime struct will have a 0-value time component, which maps to 12:00:00.000 AM.
To get around this, you need to specify the output format for your column, so that it explicitly does not include a time value. You want something like this:
((DateTime)getValue(8)).ToString("d")
However, the exact code you need will vary wildly depending on how your result table is created. If necessary, check the SqlDataReader.GetDataTypeName() function to know what type you're dealing with.
Try using the DateTime.ToShortTimeString Method ():
Console.WriteLine("Short date string: \"{0}\"\n", myDateTime.ToShortDateString());
Output: Short date string: "5/16/2001"
I have a transformation script I am running in C# within SSIS. I am simply attempting to take a date attribute from my source file and add a single day to that date. Do I really need to create a variable to facilitate this?
If you wish to perform the task of adding a day to a date attribute in C# script, then take a look at the following link:
Datetime in C# add days
Otherwise, an expression like the following applied in a derived column under data flow will also work.
DATEADD("day", 1, DateAttribute) //Apply if Attribute already is in datetime type.
DATEADD("day", 1, (DT_DBTIMESTAMP)DateAttribute) //Apply if Attribute needs to be converted to datetime type in order to then add a day.
Whether or not you need to add a variable is something I cannot answer. More information on how this attribute is applied downstream in the pipeline is required. Using variables is generally a good practice in SSIS packages. Take a look at the following very helpful link for best practices.
Best Practices
Hope this helps.
I have a grid that is populated using an Oracle 11g query that returns a TIMESTAMP(6) WITH TIME ZONE field along with other fields.
When I select a date range for data to be displayed that goes from 12/26/2014 to 1/5/2015, and then try to sort by this column (asc or desc), it does not sort properly. For example, in desc order it displays from 01/01 to 01/05 and then from 12/26 to 12/31. Looks like string sorting.
I am guessing a TIMESTAMP(6) WITH TIME ZONE field that contains a value like 21-JAN-2015 18:17:16:00000 USA/EASTERN is not recognized as a date-time but rather a string. Is there any way to resolve this issue?
Turning a comment into an answer:
There is a number of options:
(i) Rely on the database to sort the data correctly - which you might want to prevent for performance reasons.
(ii) Instruct the grid to handle the timestamp column as such (and not as a string column) - which might not be possible.
(iia) Use a different grid component, which handles date columns properly.
(iii) Use a hidden (string) column with the timestamp formatted as 'YYYY-MM-DD HH24…' for sorting.
(iv) Write your own sort routine.
Feel free to provide more detail if and as you see fit.
I have a report file(.rpt) having text as shown below and this .rpt file get updated every day.
Datum/Uhrzeit,Sta.,Bez.,Unit,TBId,Batch,OrderNr,Mat1,Total1,Mat2,Total2,Mat3,Total3,Mat4,Total4,Mat5,Total5,Mat6,Total6,Summe
41521.755934(04.09.13 18:08:32),TB01,TB01,005,300,9663, ,2,27313.63,0,0.00,0,0.00,3,1776.19,0,0.00,0,0.00,29089.82
41521.797601(04.09.13 19:08:32),TB01,TB01,005,300,9682, ,2,27365.98,0,0.00,0,0.00,3,1780.86,0,0.00,0,0.00,29146.85
41521.839269(04.09.13 20:08:32),TB01,TB01,005,300,9701, ,2,27418.34,0,0.00,0,0.00,3,1785.53,0,0.00,0,0.00,29203.88
41521.880937(04.09.13 21:08:33),TB01,TB01,005,300,9721, ,2,27473.31,0,0.00,0,0.00,3,1790.40,0,0.00,0,0.00,29263.71
41521.922606(04.09.13 22:08:33),TB01,TB01,005,300,9741, ,2,27528.53,0,0.00,0,0.00,3,1795.30,0,0.00,0,0.00,29323.83
41521.964274(04.09.13 23:08:33),TB01,TB01,005,300,9760, ,2,27580.88,0,0.00,0,0.00,3,1799.97,0,0.00,0,0.00,29380.84
41522.005942(05.09.13 00:08:33),TB01,TB01,005,300,9780, ,2,27636.00,0,0.00,0,0.00,3,1804.86,0,0.00,0,0.00,29440.86
Need to extract first and last reading values of every row and need to put that reading in database table.
first reading -- Datum/Uhrzeit
last reading -- Summe
I have used COPY command also but it doesn't take the first value. I want to know which data type to use to extract this value (it is not in normal date formats)???
Also is it not possible just to take these two readings only out of this file and not the whole 20 readings?? Is there any such method available??
I am using PostgreSQL 9.0
Any help would be great.
Assuming that "reading" = "column":
You will need to COPY to a TEMPORARY table where the first column is of type text, not date, since that is an invalid date format.
Then you can do an INSERT INTO teal_table (col1, col2, ...) SELECT some_func(thedate), col2, col3... FROM temptable to transform the temp table contents into correct date data using appropriate SQL and insert it into the real target table.
There are lots of existing examples of this on Stack Overflow, though not for your particular date format. I'm guessing that the date in the parens (...) is the date you want, and that the numbers before are a representation of that date as days since epoch + time since start of day. It'll be easier to just parse the date part, which you can do with:
SELECT to_timestamp(substring('41521.880937(04.09.13 21:08:33)' from '\(.*\)' ), '(DD.MM.YY HH24.MI.SS)');
so that's your some_func for the above.
As for taking only the two desired columns, I already explained that to you before so I'm not going to repeat myself. Short version: Use an ETL tool, re-export the CSV with just those columns, or use a filter program to limit the input.
I have a client that allows users to specify a particular format for records. Not the id, but as good as.
So the user can select a format of say
yyyy-1st 3 chrs of client name-next available file number
or
file manager initials, next file number, yy
or
next file number, yyyy, file manager initials
they can also add more items so you might get
next file number-yyyy-client initials-managers initials-yy
Having difficulty visualising the solution on this and how to store the format in a table, pull it out and generate the required number.
Especially given that the client can
change format at any time
the next file number needs to be the next one.
I guess the important piece i am missing here is to generate a query giving me the "next file number" if there are already records.
edit
not limited to sql. I just can't think of a solution that will allow me to store a number in a custom format and then generate the next number based on that format.
What we require our users to do is to reformat the existing records when they change the format. When the format is changed, we know the old format and the new format, so we can update the existing records.
If the visual record number is integral to your operations and needs to be retained, I would then keep a shadow copy in the record that contains the record number formatted according to the current format. You can update this in all records when the format is changed and finding the next available number is now a simple select statement.
I dont quite understand what you mean, but this may possible enlighten you more.
This is what I would possible do:
typedef struct tagRecord
{
Date (dd/mm/yyyy)
Initials_Client
Initials_FileManager
Next_File_Number
} Record;
...
Let: d = Date, ci = Initials_Client, fmi = Initials_FileManager, nfn = Next_File_Number
SelectFormat(record[0], "dci"); // Display Date and Initials_Client
Output: 12/4/2011 MH
or
SelectFormat(record[0], "cid"); // Initials_Client and Display Date
Output: MH 12/4/2011
If you need more pseudo-code, please ask.