Here are two more ways to insert timestamps into 4 via SQLD:

Massaging the data:

$timeStamp_t:=String(Current date;ISO date GMT;Current time)  
$timeStamp_t:=Replace string($timeStamp_t;"T";" ")  // remove T from middle of 
timestamp
$timeStamp_t:=Replace string($timeStamp_t;"Z";"")  // remove Z from end of 
timestamp
Begin SQL
INSERT INTO Table_1 (Field_2) 
VALUES (:$timeStamp_t);
End SQL

Concatenation with TS syntax and execute immediate:

$timeStamp_t:=String(Current date;ISO date GMT;Current time)  
$timeStamp_t:=Replace string($timeStamp_t;"T";" ")  // remove T from middle of 
timestamp
$timeStamp_t:=Replace string($timeStamp_t;"Z";"")  // remove Z from end of 
timestamp
$sql:="INSERT INTO Table_1 (Field_2) "
$sql:=$sql+"VALUES ({ ts '"+$timeStamp_t +"' });"
Begin SQL
EXECUTE IMMEDIATE :$sql;
End SQL



-----Original Message-----
From: 4D_Tech [mailto:[email protected]] On Behalf Of Timothy Penner
Sent: Monday, August 29, 2016 11:04 AM
To: 4D iNug Technical
Subject: RE: How to find 2 digit years in legacy Database.

Also, if you want to build a timestamp in 4D here is the format:

http://doc.4d.com/4Dv15R4/4D/15-R4/Principles-for-integrating-4D-and-the-4D-SQL-engine.300-2818873.en.html#1352502

Inserting
=======

Begin SQL
INSERT INTO Table_1 (Field_2)
VALUES ({ ts '1998-05-02 01:23:56.123' }); End SQL

Getting the data back is the same as my last email:
======================================

C_TEXT($text1)
Begin SQL
SELECT CAST(Field_2 AS TEXT)
FROM Table_1
WHERE ID = 3
INTO :$text1;
End SQL
  // $text1 = 5/2/98 1:23


C_DATE($dd)
C_TIME($tt)
Begin SQL
SELECT Field_2, Field_2
FROM Table_1
WHERE ID = 3
INTO :$dd, :$tt;
End SQL
  // $dd = 05/02/1998
  // $tt = 01:23:56

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to