Converting timestamps using strptime - R [duplicate] - arrays

This question already has answers here:
Convert numbers to dates [duplicate]
(2 answers)
Closed 9 years ago.
I have input data with date and time stamps as "140128142257" which is the equivalent of "14/01/28 14:22:57" or "%Y/%m/%d %H:%M:%S".
I cannot get R to read this in so I can convert it to a usable date and timestamp. Any helpful advice would be appreciated.
Here is what I have tried:
datetime <- as.POSIXct(strptime(date[,2],format="%Y%m%d%H%M%S")
However this just gives NA * length of array.

The uppercase %Y is used for four-digit years. You have to use %y for two-digit years.
strptime("140128142257", format = "%y%m%d%H%M%S")
# [1] "2014-01-28 14:22:57"

Related

How to get the current time in a different city in C? [duplicate]

This question already has answers here:
mktime() for non-local timezone
(3 answers)
I need to get time in California, but I am from Novosibirsk
(4 answers)
How to calculate daylight saving switchover dates for EU?
(2 answers)
Closed 2 months ago.
I'm writing a server in C that is meant to get a request over UDP for the time in either:
Doha, Prague, New York or Berlin.
How can I produce the right response?
I tried looking into the localtime() method but couldn't find anything relating to a timezone
Ok so I figured it out on my own.
Let's say I want the current time in Doha.
Apparently Doha's time is UTC+3.
Which means that I need to get the current UTC time and add 3 hours to it like so:
char* response = malloc(255 * sizeof(char));
time_t now = time(NULL);
tm* t = gmtime(&now); //Gets me the UTC time
t->tm_hour += 3; //Adds 3 hours to it
mktime(t); //Normalizes it (so it's 60 seconds in a minute, 60 minutes in an hour and so on...)
strftime(response, 255, "%H:%M:%S", t);

how to find integer length in string in T-SQL using LEN [duplicate]

This question already has answers here:
how to extract address number from string in T-SQL [duplicate]
(4 answers)
Closed 4 years ago.
I have number in string and I need length of number only in string, how can I do that?
120 westminister way Road, London (NW10 5NQ)
5 westminister way Road, London (NW10 5NQ)
select
LEN( PATINDEX('%[0-9]%', [address])) doorNoLength
output expected
i) 3
2) 1
Why not just do ?
SELECT LEN(LEFT(address, PATINDEX('%[A-Z]%', address)-1)) AS doorNoLength

Keep only first two digits after decimal with no rounding [duplicate]

This question already has answers here:
Truncate (not round) decimal places in SQL Server
(21 answers)
Closed 4 years ago.
i would like to keep only first two digits after decimal but i don't want to round or convert the value.
For example:
143,655 -> 143.65
547934,945 -> 547934,94
Converting or rounding the values doesn't work, it modifies the values.
use the ROUND() with truncate function
https://learn.microsoft.com/en-us/sql/t-sql/functions/round-transact-sql
select round(143.655, 2, 1),
round(547934.945, 2, 1)
the last parameter, when non-zero, it will truncate

SQL-Server: Store Ω (Omega) in a nvarchar field [duplicate]

This question already has an answer here:
How to insert greek characters into sqlserver table
(1 answer)
Closed 6 years ago.
If I run
create table t (c nvarchar(10));
insert into t (c)
values ('Ω');
select * from t
the output is O
O
instead of Omega
Ω
I thought I could store almost every character in a nvarchar field.
You have to use N before the character:
insert into t (c)
values (N'Ω');

function to get only the integer [duplicate]

This question already has answers here:
Issue with Round function in ssrs
(3 answers)
Closed 8 years ago.
What function I have to use to get as a Result 1 in the following expression, in SQL Server or SSRS please
select ROUND((3 - (4 * 0.32)), 1) = 1.70
FLOOR is the function that you need: http://msdn.microsoft.com/en-us/library/ms178531.aspx
select FLOOR(ROUND((3 - (4 * 0.32)), 1))
ROUND((3 - (4 * 0.32)), 0)
=> 2
ROUND()
If that is not the desired result then you probably want to use FLOOR

Resources