DataType of a Column in DataTable - datatable

I am creatin a datatable in C#,(sharepoint 2010). I want to add a column of datatype date having format "dd/mm/yyyy"
Can anyone tell me how to define a datatype for this column?
I tried this:
//SharePoint2010
table.Columns.Add("Start Date", typeof(DateTime));
To display in dd/MM/yyyy
DateTime sdt = DateTime.Parse(req["Start_x0020_Date"].ToString());
row["Start Date"] = sdt.ToString("dd/MM/yyyy");
But i am getting the output as dd/MM/yyyy HH:MM:SS
Please help i want the output as dd/MMyyyy

Add DateTime column to the DataTable and later you may format it to "dd/MM/yyyy" format.
DataTable dataTable=new DataTable();
dataTable.Columns.Add("date",typeof(DateTime));
EDIT:
No need to use DateTime column type to store string. Use string column type.
table.Columns.Add("Start Date");
..
table.Rows.Add(sdt.ToString("dd/MM/yyyy"));
//OR
row["Start Date"] = sdt.ToString("dd/MM/yyyy");

Related

converting string date to datetype in pyspark rdd

I need to convert string date to date in a rdd in pyspark shell
I have date in this format "01JAN2018:00:00:00" in date column. I need to convert this to any date format
dq1= dq.withColumn("record_date",dq['D_MTHLY_LABEL'].cast(DateType())).show()
It displays null values in the new column
Try below example.
dq.selectExpr("cast(to_date(from_unixtime(unix_timestamp(D_MTHLY_LABEL, 'ddMMMyyyy:HH:mm:ss'))) as date) record_date").show()

How can I convert a date to another format at run time in Oracle?

I have a date string coming from user input in the format of DD/MM/YYYY and I need to match it against a date column in our database in the format of DD-MON-YY.
Example input is 01/01/2015 and example date column in our database:
SELECT MAX(creation_date) FROM orders;
MAX(creation_date)
------------------
06-AUG-15
I need to query in the format:
SELECT * FROM orders WHERE creation_date = 01/01/2015
and somehow have that converted to 01-JAN-15.
Is it possible with some built-in Oracle function?
Use to_date, if the column in the table is in date format
http://www.techonthenet.com/oracle/functions/to_date.php
to_char allows you to specify different formats in a SQL statement.
Example: to_char(sysdate,'DD-MON-YYYY') will display 06-AUG-2015 for today's date.
TO_CHAR
Use to_date to compare your date column to a date string, but be careful in doing so since your date column may include a time component that isn't showing when selecting from your table.
If there is no index on your date column, you can truncate it during the comparison:
SELECT * FROM orders WHERE TRUNC(creation_date) = TO_DATE('01/01/2015','mm/dd/yyyy');
If there is an index on your date column and you still want to use it then use a ranged comparison:
SELECT * FROM orders
WHERE creation_date >= TO_DATE('01/01/2015','mm/dd/yyyy')
and creation_date < TO_DATE('01/01/2015','mm/dd/yyyy')+1;

Convert string with date text to date format in BIRT table

I have a Date which I retrieve as a string "Dec 20 2007" from my front end app and insert into a BIRT table.
Since the data type for this field is set as "Type: String" when I convert it to Date the table breaks and no data is visible in the Table.
My ultimate goal is to sort the table by Date.
Any solution to convert the string which is "Dec 20 2004" to date format in BIRT table.
Thanks.
Is is very simple, simply create a new empty column in the same table.
Add a data item with an expression like this:
new Date(row["String Date"])
http://developer.actuate.com/community/forum/index.php?/topic/36777-convert-string-with-date-text-to-date-format-in-birt-table/
Then you can sort on the new data binding.

how to do in hibernate like order by to_date(ADD_DATE_CREATED,'DD-MM-YY') desc

i want to add criteria in hibernate for order by date.
Here date description in db as
vrhCreatedDate varchar2(20)
Here i have date with varchar datatype in database .
i m doing order by using
order by to_date(ADD_DATE_CREATED,'DD-MM-YY') desc
how to add criteria like below for order by date itself ?
criteria.addOrder(Order.desc("to_date({alias}.vrhCreatedDate, 'DD-MM-YY')")); //need to parse varchar column in date when pass order by column in hibernate.
Parse order by column with string to date field.
You can use the following statment to order by your date field
criteria.addOrder(Order.desc("your Field name"));

how to insert current date into a DATE field in dd/mm/yyyy format in oracle

I have a field in my table with datatype as DATE in Oracle.
I want to insert the current date into that field, in format DD/MM/YYYY format.
I tried the below query:
select to_date(to_char(sysdate,'dd/mm/yyyy'),'dd/mm/yyyy') from dual
But it gives
1/8/2011 12:00:00 AM.
I want it to insert and show as
08/01/2011 12:00:00 AM.
Can anyone help me in this please ?
DATE is a built-in type in Oracle, which is represented in a fixed way and you have no control over it.
So:
I want it to insert [...] as 08/01/2011 12:00:00 AM
The above is nonsensical. You don't insert a string, you insert a date.
Format is useful only when you want:
to convert a string to an internal representation of date with TO_DATE (format mask: how to parse the string);
to convert an internal representation of date to a string with TO_CHAR (format mask: how to render the date).
So basically, in your example you take a DATE, you convert it to a STRING with some format, and convert it back to DATE with the same format. This is a no-op.
Now, what your client displays: this is because your Oracle Client won't display DATE fields directly and the NLS layer will convert any DATE field that is selected. So it depends on your locale by default.
What you want is SELECT TO_CHAR(SYSDATE,'DD/MM/YYYY') FROM dual; which will explicitly perform the conversion and return a string.
And when you want to insert a date in a database, you can use TO_DATE or date literals.
Alternatively, if you want to retrieve the date part of the DATE field, you may use truncate, i.e.
select to_char(trunc(sysdate),'dd/mm/yyyy') from dual;
When the column is of type DATE, you can use something like:
Insert into your_table(your_date_column) Select TRUNC(SYSDATE) from DUAL;
This removes the time part from SYSDATE.
Maybe this can help
insert into pasok values ('&kode_pasok','&kode_barang','&kode_suplier',
to_date('&tanggal_pasok','dd-mm-yyyy'),&jumlah_pasok);
note: '&' help we to insert data again, insert / end than enter to
insert again example: Enter value for kode_pembelian: BEL-E005 Enter
value for kode_barang: ELK-02 Enter value for kode_customer: B-0001
old 2: '&kode_pembelian','&kode_barang','&kode_customer', new 2:
'BEL-E005','ELK-02','B-0001', Enter value for tanggal_pembelian:
24-06-2002 Enter value for jumlah_pembelian: 2 old 3:
to_date('&tanggal_pembelian','dd-mm-yyyy'),&jumlah_pembelian) new 3:
to_date('24-06-2002','dd-mm-yyyy'),2)
1 row created.
SQL> / (enter)

Resources