Questions tagged [to-date]

to_date is sql function that converts string to date

to_date is an SQL function that converts a string to a date.

Reference

293 questions
3
votes
2 answers

postgresql cast numeric to date and format

I have my date field as numeric in postgresql and the values in the date are like 1401710352000 and when I try to convert it using to_timestamp(date) then I get the corresponding timestamp as "46388-06-07 10:40:00+00" I have tried to google it and…
Arif
  • 377
  • 2
  • 5
  • 21
3
votes
2 answers

Ruby string date to_date with try yields invalid date

I want to try get a date from params into a date format, and if it can't then i would like to then assign it to a date from a year today. This is what i tried. valid_until = params[:valid_until].try(:to_date) || Date.today.next_year The try method…
legendary_rob
  • 12,792
  • 11
  • 56
  • 102
3
votes
1 answer

Why doesn't this query fail, when converting to_date

This query runs and returns no rows. SELECT DISTINCT TO_CHAR(START_DATE,'MM/DD/YYYY'), TO_CHAR(END_DATE, 'MM/DD/YYYY') FROM …
EvilTeach
  • 28,120
  • 21
  • 85
  • 141
3
votes
2 answers

Converting to date with multiple possible masks in Oracle

It so happens that I have to get a date from a varchar2 column in oracle, but it is inconsistent in formatting. Some fields might have '2009.12.31', others '2009/12/32 00:00:00'. Is there any standard construct I could use, so that I don't have to…
Toms Mikoss
  • 9,097
  • 10
  • 29
  • 41
3
votes
1 answer

ORA-01861: literal does not match format string

I'm pretty sure this is something really silly. Instead of spending another 10 minutes with this ( or better said, while I spend another 10 minutes with this ) I'll ask it here in parallel. What's wrong with the following statement: select…
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
3
votes
1 answer

Coalesce and Case-When with To_Date not working as expected (Postgres bug?)

I'm using Postgres 9.1. The following query does not work as expected. Coalesce should return the first non-null value. However, this query returns null (1?) instead of the date (2). select COALESCE( TO_DATE('','yyyymmdd'), --(1) …
ADTC
  • 8,999
  • 5
  • 68
  • 93
3
votes
3 answers

oracle insert only time

I would like to insert data to db as time, not date. If I use to_date('2012-08-31 07:39:33', 'YYYY-MM-DD HH24:MI:SS') it adds date too. If I use to_date('09:34:00', 'HH24:MI:SS') it adds year, month, day as well, from nowhere :| Later I need to get…
user1164545
  • 129
  • 3
  • 5
  • 10
2
votes
1 answer

PostgreSQL TO_DATE query issue

I have the following PostgreSQL query: INSERT INTO persoane_alocate(pa_id_pj,pa_id_corespondent_persoana,pa_procentaj,pa_tip_persoana,pa_data_inceput,pa_data_sfarsit,pa_afisare_in_monitor,audit_data_modificarii,audit_id_utilizator) VALUES ('670',…
Psyche
  • 8,513
  • 20
  • 70
  • 85
2
votes
2 answers

Oracle Get only time from To_Date() in a Query?

I have an insert query: INSERT INTO THE_TABLE (Field_A) VALUES (TO_DATE('08/12/2011 08:35:42 AM','HH:MI:SS PM')) WHERE Something = 'SomethingElse' Field_A is a Date field. When I execute the query, Field_A still shows a date and time. Is there a…
Soren
  • 797
  • 5
  • 15
  • 32
2
votes
3 answers

Oracle: Why do I have to use TO_DATE to pull my data?

When trying to filter on EXPIRE_DATE, it seems I have to use TO_DATE. Why do I have to use TO_DATE? The EXPIRE_DATE data type in the database is ALREADY set to date. Here is the code that works. SELECT * FROM MY_TABLE WHERE EXPIRE_DATE >=…
2
votes
1 answer

Oracle Bind Variable to_date parameter Error

I am writing code which uses a Python script to execute a SQL (Oracle) statement, as shown below: PYTHON: with open(os.path.join(WORKING_PATH, "sql", "fetchCalendar.sql"), 'r') as fetch_date = fetch.read() #(Some other code) CD =…
NicholasTW
  • 85
  • 1
  • 10
2
votes
3 answers

Why ORACLE TO_DATE function does not gives an ORA-01841 error in OR condition when spaces gets passed?

SQL> select to_date(' ','YYYYMMDD') from dual; ERROR at line 1: ORA-01841: (full) year must be between -4713 and +9999, not be 0 SQL> select * from dual where to_date(' ','YYYYMMDD') = '19960512' or 1 = 2; ERROR at line 1: ORA-01841: (full)…
Shubham Khandare
  • 135
  • 1
  • 15
2
votes
2 answers

Java, time-related objects and oracle to_date function

I have an Oracle database with column called UPDATED marked in sqlDeveloper as TIMESTAMP(6). An example entry in that column is 05-MAY-18 04.49.45.000000000 I want to execute following query against it using prepared statement: SELECT * FROM…
Starryd
  • 23
  • 1
  • 4
2
votes
1 answer

Incorrect date returning when casting from varchar to date

When casting from a varchar data type to a date datatype, my query results are altering the day of the original field. For example, the below two queries select to_Date('2017-12-15 00:11:10.167664+00', 'YYYY-MM-DD') select '2017-12-15…
CJR
  • 21
  • 2
2
votes
3 answers

How to save date in ORACLE in Y-m-d H:i:s format?

In PHP, date('Y-m-d H:i:s') gives result like '2017-02-17 23:10:00' format. Now, I want to save the result in ORACLE 10g. I am using Oracle 10g Xpress Edition. Now, I am trying to save the Data like this. $sql = "INSERT INTO tbl_language VALUES (1,…
Saswat
  • 12,320
  • 16
  • 77
  • 156
1 2
3
19 20