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.
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 had this question, in one assignment, and the answer is false. Can someone explain cuz I saw couple questions here trying to do this
In most SQL databases, this is not strictly possible. However, there are a few exceptions. In SQLite, any type of data can be stored in any column. However, SQLite columns support the concept of "affinity." There are 5 affinity types, including TEXT, NUMERIC, INTEGER, REAL, and BLOB. Inserting numeric data into a column with a TEXT affinity will result in that data first being converted to text.
On other databases, such as MySQL, columns do have rigid types, but there are flexibilities in other ways. For example, MySQL supports implicit casting such that the following comparison against a numeric column col is allowed and possible:
WHERE col > '123'
In this case, MySQL will implicitly convert the string literal 123 to an integer before doing the comparison.
A column value is an atomic value.
A single atomic value has exactly one data type: the declared for the column that contains the value.
So the answer is: no, a column in a relational database (that honors the SQL standard) can not have multiple data types.
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 2 years ago.
Improve this question
In SQL Server I am using the concat function to join two columns. One column is numeric. Because of that after concat, the output shows that number in scientific notation. Is there any way to avoid that scientific notation?
I tried
concat (convert (numbercolumn as varachar), text_column)
but I get an error
concat is not a recognized built in function name
First, you don't need to explicitly convert, so:
concat(numbercolumn, textcolumn)
If this still converts to exponential, then convert to a decimal first. I'm not sure what you want things to look like but something like:
concat(convert(decimal(38, 10), numbercolumn), textcolumn)
You can also use format() or str() to convert the value to a string.
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>
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.
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.