Need to change date formate to date (YYYYMMDD) format - stored-procedures

Here the requirement is to convert sysdate to in to YYYYMMDD in date format. Here issue it converts this in string but I need this to convert in date format in YYYYMMDD form.
select to_char(trunc(sysdate-1),'YYYYMMDD') cdr_date from dual;

Would be easier to help if you mentioned what database you were using in your post or at least your tags. However based on the to_char function you are using I am assuming oracle. If that is right then the below code should help you out. I found this by simply googling oracle date format and going to the first link which is:
https://www.techonthenet.com/oracle/functions/to_date.php
Select to_date(trunc(sysdate-1),'YYYYMMDD') cdr_Date from dual;

Related

Filter Data between two Persian date in c#

Hi I want to filter my data which is between two Persian date.
Note: Persian date is a string data type like : "1400/02/23"
when I want to filter my table in SQL Server I simply write like the code bellow:
SELECT * FROM Table
WHERE Date >="1400/01/02" AND Date <="1400/05/10"
but in C# syntax I do not know how to fetch date between two string to use in my filter back-end code. If I simply compare the error raise that string type data can not use comparison operator.
I would be glad and grateful if somebody help me
First, convert Persian Date to Gregorian date and then do the comparison.

Data retrieving from sqlite DB between two dates - using objective c

I am using the below query with date filtering, but I am getting wrong result.
SELECT * FROM TRANSACTIONSHISTORY
WHERE DATE > "29-01-2015 12:00:00"
AND DATE < "30-01-2015 00:00:00" AND USERID=abc
I am getting result with date column with value of 29-Jan-2016 records, what am I missing here, can any one help me to get out of this value.
The date format in your SQL will not work because SQLite doesn't have a native datetime type, so it's generally stored either as a string, in YYYY-MM-DD HH:MM:SS.SSS format, or as an numeric value representing the number of seconds since 1970-01-01 00:00:00 UTC. See date and time types on SQLite.org. Note that if you're using the string representation that the sequence is year, month, day (which, when sorting/querying this string field, the this alphanumeric string will sort correctly by year first, then month, and then day, which is critical when doing queries like yours).
If you really stored dates in the database as a string in the DD-MM-YYYY HH:MM:SS format, you should consider changing the format in which you saved the values into one of the approved date formats. It will make the date interactions with the database much, much easier, allowing queries like the one you asked for (though, obviously, with DD-MM-YYYY replaced with YYYY-MM-DD format).
You have cast your string to Date
SELECT * FROM TRANSACTIONSHISTORY WHERE DATE between Datetime('29-01-2015 12:00:00') and Datetime('30-01-2015 00:00:00') AND USERID=abc
The first answer is exactly what you need. What you did in your code would be comparing strings using ASCII values.
I would recommend you to use the linux time stamps like: 1453818208, which is easier to save and compare. In addition, it can always be translated to human-readable dates like: 29-01-2015 12:00:00.
SELECT * FROM TRANSACTIONSHISTORY
WHERE DATE > "29-01-2015 12:00:00"
AND DATE < "30-01-2015 00:00:00" AND USERID=abc
I hope this helps you :)
Try this first try without Time,after that try date and time both , Hope i will work for you
SELECT TRANSACTIONSHISTORY
FROM SHIPMENT
WHERE DATE
BETWEEN '11-15-2010'
AND '30-01-2015'
// you can try this one also
SELECT * FROM TRANSACTIONSHISTORY WHERE DATE BETWEEN "2011-01-11" AND "2011-8-11"

Date format in Talend

I am facing an issue with Talend dates. I have tried several solutions but still an "unparseable date" error persists.
My date format is of the form : 24/12/2013 16:25:47.328000000
I have tried:
TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSSXXX",row1.REGISTERED_ON,true),
TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss",row1.REGISTERED_ON,true)
but still I get that same error.
Can anyone help shed some light please?
I'm not familiar with Talend, but you say
My date format is likewise : 24/12/2013 16:25:47.328000000
and
I have tried
TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSSXXX",row1.REGISTERED_ON,true),
TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss",row1.REGISTERED_ON,true)
but the date you specify is in dd/MM/yyyy format. I imagine that's the cause of your problems.
I am Able to parse given string date using below format, below statement should work for you,
Input String "24/12/2013 16:25:47.328000000"
Format: "dd/MM/yyyy HH:mm:ss.SSSS"
System.out.println(TalendDate.parseDate("dd/MM/yyyy HH:mm:ss.SSSS", "24/12/2013 16:25:47.328000000"));
See more formats on "How to parse String to Date"
to manage date in talend what i prefer to do is
1) set data type of your_date_column to string in your input file
2) parse your_date_column at the time of mapping using
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(your_date_column)
3) set data type of our output_date_column to Date with date pattern :- "yyyy-MM-dd HH:mm:ss"
Hope it will Work :)

Datatype mismatch when querying DBase Date field via a Delphi ADO Query

I'm trying to resolve a bug in a archaic reporting tool that generates SQL dynamically and I'm running to a problem where I get a Data type mismatch error when the generated SQL queries a Date field from a Dbase table.
I've managed to replicate the same problem in a simple test app where the below query is loaded into a TADOQuery and activated.
SELECT *
FROM [QPERFSAL.DBF] QPERFSAL
WHERE ( QPERFSAL.PERFDATE = '21/01/2014' )
its obviously related to the date formatting but I've tried numerous formats but I still get the error
e.g. dd/mm/yyyy, mm/dd/yyyy, yyyy/mm/dd etc.
The obvious fix would be to used parameterised queries but as this is generated on the fly by a report tool, I can't use parameters :(
Is there something I'm missing or can I specify the date format at the ADO connection?
Thanks!
VFP OleDB Provider I believe also recognizes the DATE() function where you don't need to worry about yyyy-mm-dd or mm-dd-yyyy or dd-mm-yyyy formats. It will build into a proper date format column.
where QPERFSAL.PERFDATE = date( 2014, 1, 21 )
Now, if the "perfDate" column is that of a date/time, then you need to compare based on the date-only portion of the date/time field by using TTOD() (time-to-date function)
where TTOD( QPERFSAL.PERFDATE ) = date( 2014, 1, 21 )
Try to use as follows:
SELECT *
FROM [QPERFSAL.DBF] QPERFSAL
WHERE ( DTOC(QPERFSAL.PERFDATE) = '01/21/2014' )
Firstly, thanks to all that posted suggestions.
Alas, I tried them all but without success :(
thankfully, I found the solution while searching for something unrelated.
SELECT *
FROM [QPERFSAL.DBF] QPERFSAL
WHERE PERFDATE = Format('2014/12/06',"YYYY/MM/DD")
I'm not sure what effect this will have on localization but at least I can get the query to run now.

issue to query data filtered by Date from fusion table

I'm trying to write a small javascript code to query data filtered by date.
If I write the following sentence in my browser, I can get data :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883"
but if I write the same thing, except I want only data after a certain date :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883 WHERE Date > 2/29/12"
From the SQL-like API, https://developers.google.com/fusiontables/docs/developers_reference#Select, it should work
I get an error witch is "'internal_error', message:'Could not parse query'"
-Date is a DATETIME format in my fusion table.
-I've tried different format, but I can not get data.
What am I doing wrong?
Thank you very much for your help.
The Date value must be quoted and the format is MM/dd/yy so you must pad single digits with leading zeros.
I had success with:
select Date,Poids from 3049883 where Date >= '02/29/12'
Note: I did not test with gvizdata, just with the FT JSONP API

Resources