Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have time stamp in oracle db in following format (6/23/2017 12:00:00.000000 AM).
I need to convert it into YYYYmmddHHMMSS format.
I have tried to convert using
`to_char(time,"YYYYmmddHHMMSS")`
but it is giving like 20170623120600. Instead of minutes it is giving months.
Please suggest.
you should give MI for minutes. so your conversion will go like this
to_char(time,'YYYYmmddHHMISS')`
You have to use MI instead of mm to mention minutes, oracle doc is your friend
You need to first convert string to TimeStamp then convert it to your respective format.
You can try as below:
Select
To_Char(
To_TimeStamp('6/23/2017 12:00:00.000000 AM', 'MM/DD/YYYY HH:MI:SS.FF AM'),
'YYYYmmddHHMISS')
from dual;
I have time stamp in oracle db in following format
No, there is not format for datetime when it is stored in the database. The format you see is only for display.
Instead of minutes it is giving months.
It is obvious because you have used MM instead of MI.
MM gives you the month number
MI gives you the minutes in the time pportion
so, use:
to_char(time,YYYYMMDDHHMISS)
For example,
SQL> SELECT to_char(SYSDATE,'YYYYMMDDHHMISS') FROM dual;
TO_CHAR(SYSDAT
--------------
20150415050759
SQL>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have an export of all my signal text messages that I've decrypted. One of the stages was the conversion of an SQL database into a CSV, so I now have a large CSV that looks like this:
The fields are _id thread_id date date_sent body if that's not readable.
I want to convert the date & date_sent to something like YYYY-MM-DD but right now they're in a SQL format like 1568610000000 or 1590550000000. Is there an easy way to convert these? I searched for about an hour before asking, but most q's are about how to convert a SQL into a CSV not how to manage exported SQL data in a CSV.
It looks like you have the file stored in Excel (from looking at the 1.59E..). If you can add a few more columns then it's simple to calculate a "proper" date formatted for SQL servers in ISO format.
If your "date" column is D, you can do
=D1/86400000+DATE(1970,1,1) and then format this cell as date (YYYY-mm-dd).
The date number 1,56861E+12 will become 2019-09-16 05:00:00
Note that the formula is for English Excel, you may have to rename for formula and replace comma with semicolon.
to calculate without Excel you can use the algorithms listed on the Epoch Converter - your timestamp is Unix Epoch in Miliseconds.
I am creating a custom audit log as a process in the Apex application I have developed.
Below is the code I have used to log the actions by the user when they use the application. The LOGON_DT and LOGOFF_DT will only need to be in a date format. However, QUERY_SEARCH_TIME will need the time.
INSERT INTO AUDIT_LOG
(USERNAME, ORDER_NO, ORDER_NAME, CUSTOMER_NAME, LOGON_DT, LOGOFF_DT, QUERY_SEARCH_TIME)
VALUES
(:APP_USER, :P10_ORDER_NO, :P10_ORDER_NAME, :P10_CUSTOMER_NAME, SYSDATE, SYSDATE,
SYSDATE(HH24:MI:SS));
The above code works perfectly when HH24:MI:SS is taken off, and I'm not sure where I'm going wrong with this?
Any guidance will be great. Thank you!
Oracle has it's own internal representation for a DATE datatype. You can't dictate its format in the way you are attempting.
It is common to apply a date format on retrieval, which you can do by applying the appropriate format mask as you convert to a string.
TO_CHAR(QUERY_SEARCH_TIME, 'HH24:MI:SS')
A DATE column already captures a time component. It may not be necessary to cut it off. And if you do, you do not want a DATE column as such a column will always capture a whole date, and what would be the point if you want only time.
To visualize the time component of a date you have to apply a format mask to it:
TO_CHAR(SYSDATE, 'HH24:MI:SS'). If you want to capture just that, the time, then change the datatype of the column to a VARCHAR2 type of sufficient length for the format mask you apply.
Read up on datetime datatypes here: Oracle documentation on datetime types
Read up on datetime format models here: Oracle documentation on format models
If you need time part of date only for output, you can use answer of Tom, but if you really need to store time part only, you can calculate it as
sysdate - trunc(sysdate)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have data in SQL Server with a data type of decimal(19, 6).
When trying it convert to custom format I failed.
For example;
The unformatted data: 1050.850000
I want to convert it to 1.050,00
How can write this in T-SQL?
Decimals, dates, integers etc have no format. They are all binary values. Formats apply only when you want to create a string from the value or parse a string to a value.
In SQL Server 2012+ you can use the FORMAT function to format a decimal in a custom format, eg:
declare #data decimal(19,6)=1050.850000
select FORMAT(#data,'#,###.00')
The syntax of the format string is the same as .NET's
Your desired output truncates the decimals yet displays the value with decimals. In case this isn't a typo, you can either replace the decimals with literals, eg:
select FORMAT(#data,'#,###\.\0\0')
Or truncate the value before formatting
declare #data decimal(19,6)=1050.850000
select FORMAT(floor(#data),'#,###.00')
In previous SQL Server versions you are restricted to the predefined money type formats of the CONVERT function :
select CONVERT(nvarchar,cast(#data as money),1)
Note that nvarchar defaults to nvarchar(30). Strings larger than 30 characters will be truncated to the first 30 characters.
Again, if you want to truncate the decimals, use the FLOOR function.
The older version of date format is dd-mon-yy. In that case yy represents year. But if we write 31-aug-14 in oracle 10g the full date format is 31-aug-1914.
The newer version of date is dd-mon-rr. So in that date format what does rr represent? I know that it represents 21st century but what does rr mean? Please I want to know. I asked my faculties but they also don't know.
RR means the programmer was too lazy (or ignorant) to use YYYY. Seriously.
The RR mask was introduced in the late nineties as a kludge for the Y2K problem. It was intended to help database programmers finagle input data, because changing screens was a lot more labour intensive. It substitutes a default century of a date entered without one. YY just substitutes the current century. However, in the last years of the last century that would often not be what was intended: in 1999 it was more likely that a two-digit year like 01 would be two years in the future (i.e. 2001) rather than ninety-eight years in the past (1901).
This background is important: it explains why RR pivots around 2000. So, RR prepends 50-99 with 19 and 00-49 with 20. Consequently RR will increasingly often default to the wrong century. It was only supposed to be a stopgap for legacy code: there is no excuse for using it in new applications.
To quote the Oracle documentation:
The RR datetime format element is similar to the YY datetime format element, but it provides additional flexibility for storing date values in other centuries. The RR datetime format element lets you store 20th century dates in the 21st century by specifying only the last two digits of the year.
Source: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#SQLRF00215
So basically it allows you to only specify 2 numbers of the year and Oracle will handle the century for you. In the documentation, you will also find the logic behind this. Another use is the use in queries:
The RR datetime format element lets you write SQL statements that will return the same values from years whose first two digits are different.
This question already has answers here:
How do I format date and time on ssrs report?
(11 answers)
Closed 9 years ago.
I am working with SSRS 2008. I am needing to format the date time. I am currently using this expression
=FormatDateTime(Parameters!startdate.Value)
the output of this expression is
1/22/2014 6:00:00 am.
I would like it to say just
1/22/2014
What would i need to do to this expression to make the output look this way?
Thanks in advance.
try something like
=Format(Parameters!startdate.Value,"dd/MM/yyyy")
You should use the Format property of the Textbox for this and format data in the expression only as a last resort. Select the textbox and look for Format in the property window. There you can enter the format string like dd/MM/yyyy without quotes.
That will keep your expression clean (in fact, you won't need an expression at all) and as an added bonus will allow exporting the value to excel as a datetime so you won't get datetime format conflicts later.
If your datetime is only a part of the text, you can even create a placeholder and put the format on that placeholder. Example textbox:
The time is [#startdate].
When you enter this, [#startdate] becomes a placeholder with your parameter and you can select it and set a format on it. No expressions needed.