This topic is locked
[SOLVED]

 Data Imports - Date Format Issue

5/1/2019 6:22:50 AM
ASPRunner.NET General questions
M
Mack88 authorDevClub member

I'm having an issue or two with importing data from an Excel file. I want to insert the date that the record was created and would prefer not to provide that as part of the import records. I've set the "DateCreated" field to read only with a default value of DateTime.Now. This works fine for records created via the UI ... data is correctly saved in local (Australian) format. However, when the data are imported, nothing is saved to the "DateCreated" field. Thenother fields are imported perfectly. If I use the Before Insert Record event, and provide some code:



// Fetch the last record serial number issued:

dynamic record;

dynamic rs = DB.Query("select * from Dockets where IDDockets = '105'");

record = rs.fetchAssoc();
// Autoincrement the record serial number:

var NextNumber = record["LastNumber"];

NextNumber = NextNumber + 1;

values["IDCAPANo"] = NextNumber;
// SAve the created date and last change baseline date:

var TimeChange = DateTime.Now.ToString();

values["DateCAPACreated"] = DateTime.Now.ToString();

values["LastChange"] = DateTime.Now.ToString();
// Save the new serial number in the Dockets table:

string strSQLUpdate = "update Dockets set LastNumber = " + NextNumber.ToString() + " where IDDockets = '105'";

DB.Exec(strSQLUpdate);
// Insert the record:

return true;


that date is always in US format, despite the field format being dd/MM/yyyy. So records entered today (May 1, 2019) display as January 1, 2019 and I haven't yet cracked the magic to save it in local (Australian) format. Specifying a string format (e.g. DatTime.Now.ToString("dd/MM/yyyy")) doesn't seem to make any difference, nor does a format of "yyyy-mm-dd" as suggested in a 2013 post.
I'd really appreciate some help.
Thanks in advance
Chris
[size="2"]Enterprise x64 10.1 build 32686[/size]

admin 5/1/2019

In regards to getting DateTime value in required format check this:

https://stackoverflow.com/a/32749/10969

M
Mack88 authorDevClub member 5/2/2019



In regards to getting DateTime value in required format check this:

https://stackoverflow.com/a/32749/10969


Thanks Sergey. I couldn't get that approach to work ... but I did discover . I did find this code in the ASPR manual:



values["DateCAPACreated"] = new XVar (DateTime.Now);

values["LastChange"] = new XVar (DateTime.Now);


Works perfectly! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=87679&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />