FAQ Database Discussion Community


How to use java.time.ZonedDateTime to generate a primitive long value in UTC

java,performance,coding-style,utc,data-type-conversion
What is a fairly efficient but most importantly a clean and concise way of generating a UTC timestamp as a long value (java primitive type). I only need this to be accurate to the most precise millisecond value. I would prefer to use java.time.ZonedDateTime as it is a clean way...

Parse a date from a text file and convert the month to a number

java,string,int,data-type-conversion
I have a text file display the following: Date Opening Closing 6-Mar-2006 11022.47 10958.59 9-Jun-2006 11005.66 10972.28 7-Dec-2006 10957.31 10980.69 28-Feb-2006 11096.75 10993.41 8-Mar-2006 10977.08 11005.74 How can I read in this file and convert all the months in String to month in int display. "Mar" to 3, "Jun" to...

Java integer to hex and to int

java,integer,hex,data-type-conversion
I have the problem, that the method does not work as expected. In most cases it works. However there is a case it does not work. I have a byte array containing some values. In hex e.g.: 0x04 0x42 (littleEndian). If I use the method convertTwoBytesToInt, I get a really...

How does the ternary operator evaluate the resulting datatype?

java,data-type-conversion,ternary-operator
Given this piece of code public class Main { public static void main(String[] args) { foo(1); foo("1"); foo(true?1:"1"); foo(false?1:"1"); } static void foo(int i){System.out.println("int");} static void foo(String s){System.out.println("String");} static void foo(Object o){System.out.println("Object");} } This is the output I get: int String Object Object I can't understand why in the last...

Addition on two blank objects or blank arrays in javascript

javascript,data-type-conversion
I was just playing around with javascript when i found the following console outputs: [] + [] // output: "" [] + {} // output: [object Object] {} + [] // output: 0 {} + {} // output: NaN Could anyone please explain me the logic behind these output. I...

Convert datatype Clob to Varchar2 Oracle

sql,oracle,data-type-conversion,clob,varchar2
I have an Oracle table with a column of type clob. I want to preserve the column order and change the datatype to a varchar2. The column just contains text. update IN_MSG_BOARD set MSG_TEXT = null; alter table IN_MSG_BOARD modify MSG_TEXT long; alter table IN_MSG_BOARD modify MSG_TEXT varchar2(4000); I'm getting...

how to convert a factor variable into a numeric - using R

r,variables,numeric,data-type-conversion,recode
I have another problem and hope for your help. I googled already, asked a friend and tried to understand similar problems/questions around this website, but I still can't figure it out... Ok so here's my problem: I have a large data set that covers data from 1980-2012. I used the...

Why I receive warning in objectForKey method?

objective-c,nsdictionary,data-type-conversion
I need to execute method in - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section I have an NSDictionary from which I want to get ID (long) and send it to my method: long sect = (long)section; [objectp.methodA countRowsInSection:[tableSections objectForKey:[NSString stringWithFormat:@"%ld", sect]]] I receive warning: Incompatible pointer to integer conversion sending 'id' to parameter of...

Remove line breaks “\n” in R

r,date,line-breaks,data-type-conversion,factors
I have been trying to remove the line breaks from a data set in R. All the columns are factors hence before i could replace the "\n" with "NA", i need to change the data type from factor to character or Date. I am mentioning my code and a sample...

Insert character to a number datatype column

sql,database,oracle,oracle11g,data-type-conversion
Note: I cant change the datatype of column I want to store a character into a table that has column with number datatype. The work around i found is convert the character values to ASCII and when retrieving it from the database convert it back to character. I used couple...

Convert a date to a day number (monday = 1, tuesday = 2) in R

r,date,numbers,rstudio,data-type-conversion
Can someone help me with the following: I have a date, for example: 3-1-2014, And I would like to convert this to the number 5, because it is a friday. So 7-1-2014 would be 1, because it is a monday. Which package/code can do this for me? Thanks...

Processing data before saving to database Django Tastypie

django,timestamp,tastypie,data-type-conversion
I send a string to the server and I want to convert it to a Timestamp before saving in the database. I want to do this function before saving the data. date = time.strptime(date, "%Y-%m-%d %H:%M:%S") date is sent as a string and I want to convert it to a...

What does rank mean in relation to type conversion?

c++,type-conversion,implicit-conversion,data-type-conversion,rank
From C++11 standard (draft n3337) §5/9: — If both operands have the same type, no further conversion is needed. — Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank shall be converted to the type...

Converting dataframe to dataframe in R? Unexpected results

r,data.frame,data-type-conversion
I need to do many conversions at once ina certain file I'm running. I do not understand why converting something twice results in a different output. given x = c(140,190,190,185,195,195,195,130,150,125,50,30,15,45,55) y = c(150,195,190,190,190,200,195,140,30,20,125,25,45,65,70) This, locs <- data.frame(x=x,y=y) ...works as expected, with two columns named x and y. However, if I...

Change datatype of entire database SQL

sql,sql-server-2012,data-type-conversion
I am trying to change the datatype to decimal(30,10) from float. The issue is i have a big database with more than 300 tables and they are all constrained with index and also joins. Can anybody help me with the shortcut i can use to change the datatype in entire...

Possible lossy conversion from int to byte Java

java,byte,data-type-conversion
Java neophyte here. We are coding something to just create, initialize, and print each of the primitive data types in Java. We can create and reassign values fine, but printing the values is not working. We are successful for printing the int type, but we get the error "Possible lossy...

Bytes form nginx logs is mapped as string not number in elasticsearch

nginx,elasticsearch,logstash,data-type-conversion
recently I deployed ELK and started forwarding logs from nginx through logstash frowarder. Problem is, that in elasticsearch (1.4.2) / kibana (4) is "bytes" value of request mapped as string. I uses standard congfiguration found everywhere. Into logstash patterns added new pattern for nginx logs: NGUSERNAME [a-zA-Z\.\@\-\+_%]+ NGUSER %{NGUSERNAME} NGINXACCESS...

Convert string built bit map (100101) to int value in SQL

mysql,types,data-type-conversion
Is it possible, and how would I go about converting a string representation of a bit mapping such as '10010' to cast it as the integer value it represents? We are using a string built bit map for permission settings, and I need to then cast it to the integer...

What is the difference between these data type conversions? [duplicate]

c#,data-type-conversion
This question already has an answer here: Difference between casting and using the Convert.To() method [duplicate] 7 answers Conversion #1: int result = (int)command.ExecuteScalar(); Conversion #2: int result = Convert.ToInt32(command.ExecuteScalar()); I want to know their specific use, thanks!...

Split uint16_t in bits in C

c,data-type-conversion
Hello I have a uint16_t number and I need to split it in 3 parts. The first 5 bits of this number gives me the hour. The next 6 bits of this number gives me the minutes. The next 5 bits of this number gives me the seconds. So I...

Assembly Language - Converting Two's Complement Hexadecimal to its Base 10 Equivalent

assembly,hex,decimal,data-type-conversion,base
I am currently trying to figure out how to make the correct conversion from two's complement hexadecimal to its base 10 equivalent. We were given an assembly language program that adds and subtracts 32-bit integers and need to take the values of the registers and convert them. Here is what...

Precision, Rounding, and data types in XSLT2.0

xslt,decimal,rounding,xslt-2.0,data-type-conversion
This is a question about precision, rounding, data types, and using the xs:integer() function in XSLT 2.0. We have the following line of code: <xsl:value-of select="xs:integer(round(InvoiceAmount * 100))"/> When the value of InvoiceAmount in the source XML is -62.84, the result of the value-of is -6283 which is incorrect. We...

Identifying Data Type From Binary File

javascript,file,binary,data-type-conversion,8bit
Using javascript, I want to read data from a file that looks like this: 1003 0000 1b0c 0900 0300 1000 0003 0200 0a00 0302 1102 030c 1b00 1a03 0000 0100 1200 030a 090c 1b00 0307 1000 1003 1400 What data type is this? Is it a collection of 8-bit unsigned...

Role of qw and math manipulation in Perl

arrays,perl,math,data-type-conversion
I do not understand the role of qw in Perl, which I understood in in debugging the code in this thread. Its manual is very limited here: qw/string/. I am trying to understand what goes wrong in the following code I am doing simple manipulation to the data (multiplying by...

SSIS Import a date and time from a txt to a table datetime

sql-server-2008,datetime,ssis,data-type-conversion,data-conversion
So I want to import a datetime from a txt: 2015-01-22 09:19:59 into a table using a data flow. I have my Flat Source File and my destination DB set up fine. I changed the data type for the txt input for that column in the advanced settings and the...

Why converting numpy.ndarray to custom data type using numpy.ndarray.astype multiplies my data?

python,arrays,numpy,data-type-conversion,custom-data-type
Executing this code: import numpy as np py_list = [2013, 8, 0.6552562894775783] custom_type = np.dtype([ ('YEAR',np.uint16), ('DOY', np.uint16), ('REF',np.float16) ]) NumPy_array = np.array(py_list) NumPy_array_converted = NumPy_array.astype(custom_type) print 'custom_type is:' print custom_type print '---------------------------------------------' print 'py_list is:' print py_list print '---------------------------------------------' print 'NumPy_array is:' print NumPy_array print '---------------------------------------------' print...

sql BIT to Java [closed]

java,sql-server,jdbc,types,data-type-conversion
My sqlserver table has a column designed as a BIT datatype. It has values 1 and 0s Then in my Java code, I do result = new ArrayList result.add( (Boolean)(rs.getBoolean("columnName"))); Then when I read the value from the list - it shows as Long. According to everything I find, it...

Cast error in C# for datatype short [duplicate]

c#,data-type-conversion
This question already has an answer here: Integer summing blues, short += short problem 5 answers A basic question about int and short in C# Why am I getting a syntax error for this code: for (short i = 0; i < list.Length; i++) { short key = i...

R: Convert hours:minutes:seconds

r,datetime,data-type-conversion
I have a vector "Time.Training" in the format hours:minutes:seconds (e.g. Time.Training<- c("1:00:00", "0:45:00", "0:30:00", "1:30:00") I would like to convert this into minutes in the format: Time.Training.Minutes<-c(60, 45, 30, 90) I'm wondering if someone has a straightforward method of doing this in R. Many thanks. Matt...

SQL Server 2012 How to change the data type of a column from bit to datefield?

datetime,sql-server-2012,bit,data-type-conversion,sqldatatypes
I have a table Person with a column called onvacation. This column is of data type bit since it's a boolean in the code. It has values null, 0 and 1. I would like to change the data type of this column from bit to datetime so that all values...

Arduino data type confusion. Have string, need const char?

c,arduino,data-type-conversion
I'm working with an UNO and I'm using maniacbug's RF24 library with soft spi, and his rf24network library. https://github.com/maniacbug/RF24Network All I'm trying to do is send data but I'm stuck with the wrong data type. { last_sent = now; printf("Sending...\r\n"); const char* hello = "Hello, world!"; RF24NetworkHeader header(/*to node*/ other_node);...

Java - How to Compare Char[] Array with String?

java,string,char,data-type-conversion
I have a question regarding the comparison of the characters within an Array with a specific input which is a String. I seem to have a problem at line where it states: String[] oneRow = alphabet[i]; package MemoryGame; import java.util.Scanner; public class Memory { /* * array list of the...

DateTime format string for invalid Format string

c#,datetime,format,data-type-conversion
I am trying to format Datetime string using date.ToString(format) If user feeds in wrong format, e.g. "YYYY MM DDr" I would like to know whether I can convert datetime using that format, rather than returning 2015 04 DDr since DateTime.ToString(format) always returns a valid String. For example, is there any...

(Oracle) convert date string to datetime

sql,oracle,datetime,data-type-conversion,timestamp-with-timezone
How to convert a date string with the following format into datetime when running a select statement? 2015-06-04T02:58:00.134+08:00 It is stored in a column with data type VARCHAR2(100 BYTE). Thanks!...

Take space separated input having different data types

python,data-type-conversion
I am trying to input 4 values into 4 variables that are separated by space in the user input. For example : a b 2 5 The first values two are characters, while the other 2 values are of int datatype. How can I do this?...

convert string generated from Number.toString to number

javascript,string,data-type-conversion
I use Number.toString method to convert numbers to string. Number(100).toString(16); Number(1000).toString(36); How can I convert them back to the original numbers?...

Setting Minute and Second component of Timestamp field to 0

sql,database,timestamp,teradata,data-type-conversion
I have a requirement such that if I enter a timestamp(yyyy-mm-dd hh:mm:ss) say 2015-04-05 16:45:12 I need it converted to 2015-04-05 16:00:00 Is there an elegant way to do this in Teradata rather than extracting hour and then casting it with date?...

How to convert Tiff to IMG (ERDAS) format using R programming?

r,image,tiff,data-type-conversion
I have hundreds of satellite images in Tiff format in a working directory, that firstly, must be multiplied by 2 , then converted to IMG (ERDAS) format, but in the same name as input file. For example: input: MOD11A1_2009-04-01.LST_Day_1km.tiff output: MOD11A1_2009-04-01.LST_Day_1km.img So, the first step is to multiply by 2...

My code does not run for large values of n

c,variables,integer,data-type-conversion
This code runs for values of n of the order of 100k but when it gets to a million it stops and crashes. #include <stdio.h> int main() { int i; long int n, sum; n = 1000000; int f[]; f[0] = 1; f[1] = 2; sum = 0; for (i...