convert datatype from DATE and TIME into TimeStamp

Hi, I am trying to achieve the following in sql.

curDate variable gives  2018-09-10
Hr variable gives  21:50:30

I am trying to create timestamp by concatenate both datatype into timestamp datatype.

DECLARE curDat DATE;
DECLARE Hr TIME;
DECLARE timeset TIMESTAMP;
.
.
.

SET timeset= curDat+" "+Hr;

Open in new window


How to converter the data into timestamp datatype.
Rama TitoProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
SQL Is a query language.  What database are you using?
0
pcelbaCommented:
Timestamp does not necessarily represent the date and time.  E.g. SQL Server timestamp is incremental bigint value incremented on each data row update which results in unique timestamp values across the whole database. You cannot create timestamp from date and time on SQL Server.

More about SQL Server time stamps: http://aspalliance.com/1785_Understanding_TIMESTAMP_ROWVERSION_in_SQL_Server.5

OTOH, SQL Server offers CURRENT_TIMESTAMP function which is equivalent to GETDATE().
You may also create datetime value from your date and time using the CAST or CONVERT functions.
0
Dale FyeCommented:
in SQL Server, the timestamp data type is not a date/time value but is a value that SQL Server uses to keep track of row versions and prevent read/write conflicts.

I think what you really want is to add those to values to generate a true datetime value.  Is that accurate?

As slightwv mentioned above, what RDBMS are you using (Access, SQL Server, Oracle, MySQL, ...)?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

pcelbaCommented:
MySQL and Oracle handles timestamps as datetime values and offers e.g. TIMESTAMP() function (MySQL). See  https://www.w3schools.com/sql/func_mysql_timestamp.asp for more details.

SQL Server allows following datetime value creation from date and time
DECLARE @curDat DATE;
DECLARE @Hr TIME;
DECLARE @timeset datetime;
DECLARE @timeStamp timestamp;

SET @curDat = '2018-09-10'
SET @Hr = '21:50:30'
SET @timeset = @curDat + CAST(@Hr AS datetime)
SET @timeStamp = @@DBTS

SELECT @curDat, @Hr, @timeset, @timeStamp

Open in new window

As you may see the timestamp value does not change if you don't execute any data updates.
It will be similar for other SQL dialects.
0
Rama TitoProgrammerAuthor Commented:
Hi Experts,

I am using Mariadb. i am aware about datatype. I need to convert the both datatype into TIMESTAMP.

DECLARE curDat DATE;
DECLARE Hr TIME;

Is that possible.
0
PortletPaulfreelancerCommented:
Use ADDTIME()

Then convert to timestamp
0
Rama TitoProgrammerAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.