Forums: [SOLVED] Data Imports - Date Format Issue - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] Data Imports - Date Format Issue Rate Topic: -----

#1 User is offline   ChrisN 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 50
  • Joined: 01-November 14

Posted 01 May 2019 - 10:22 AM

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

Enterprise x64 10.1 build 32686
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16435
  • Joined: 03-February 03
  • Gender:Male

Posted 01 May 2019 - 11:30 PM

In regards to getting DateTime value in required format check this:
https://stackoverflo...m/a/32749/10969
Best regards,
Sergey Kornilov
0

#3 User is offline   ChrisN 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 50
  • Joined: 01-November 14

Posted 02 May 2019 - 08:34 AM

View Postadmin, on 02 May 2019 - 09:30 AM, said:

In regards to getting DateTime value in required format check this:
https://stackoverflo...m/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! :D
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users