# Converting BIGINT to DatePicker

**URL:** <https://community.forestadmin.com/t/converting-bigint-to-datepicker/278>\
**Category:** Help me!\
**Created:** [May 22, 2020, 10:25am UTC](https://community.forestadmin.com/t/converting-bigint-to-datepicker/278 "2020-05-22T10:25:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bojan\_Antonijevic](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/bojan_antonijevic/32/205_2.png) [@Bojan\_Antonijevic](https://community.forestadmin.com/u/Bojan_Antonijevic)\
**Post date:** [May 22, 2020, 10:25am UTC](https://community.forestadmin.com/t/converting-bigint-to-datepicker/278/1 "2020-05-22T10:25:44Z")

</div>

Hi All,

We are facing an issue with converting the BIGINT field from our database to DataTypes.DATE format on the forest admin side.

Value from our DB: 1582194823  
FA field in model:

```javascript
expirationTime: {
      type: DataTypes.DATE,
      field: 'expiration_time',
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
    },

```

## Expected behavior

Expectation: 2020-02-20

## Actual behavior

Actual: 1970-01-19

 ![Screenshot 2020-05-22 at 11.52.48](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/02b13a0dc386101ede12f58209862b4564d995d9.png)

## Failure Logs

And on update a field we have an error:  
` Data truncated for column 'expiration_time' at row 1`

## Context

Please provide any relevant information about your setup.

- Package Version: 0.0.1
- Express Version: ~4.16.3
- Sequelize Version: ~5.15.1
- Database Dialect:
- Database Version:
- Project Name: tymeshiftfa

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [May 22, 2020, 11:58am UTC](https://community.forestadmin.com/t/converting-bigint-to-datepicker/278/2 "2020-05-22T11:58:06Z")

</div>

Hi @Bojan_Antonijevic,

Welcome to Forest Admin Community 👋 !

I don’t think you specify DataTypes.DATE to cast it. It does not work like that as sequelize will try to save it like that in database `2019-01-02` so it cannot work.

I think you could try to use a `TIMESTAMP`:

```javascript
expirationTime: {
      type: 'TIMESTAMP',
      field: 'expiration_time',
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},

```

If it does not work, a solution could be to create a smart field. So you would declare first your expirationTime like that:

```javascript
expirationTime: {
      type: DataTypes.BIGINT,
      field: 'expiration_time',
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
    },

```

And then create a smart field like so:

```javascript
collection('myModel', {
  fields: [{
    field: 'expirationTimeDate',
    type: 'Date',
    get(record) {
      return new Date(record.expirationTime);
    },
    set(record, expirationTimeDate) {
      // I don't know if expirationTimeDate is a date here or a string. I will consider it as a Date
      record.expirationTime = expirationTimeDate.getTime();
      return record;
    },
});

```

I hope that helps 🙏

---

<div class="post-metadata">

**Author:** ![Bojan\_Antonijevic](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/bojan_antonijevic/32/205_2.png) [@Bojan\_Antonijevic](https://community.forestadmin.com/u/Bojan_Antonijevic)\
**Post date:** [May 27, 2020, 7:50am UTC](https://community.forestadmin.com/t/converting-bigint-to-datepicker/278/3 "2020-05-27T07:50:45Z")

</div>

> [@Bojan\_Antonijevic](#):
>
> Data truncated for column ‘expiration\_time’ at row 1

Hey @vince ,  
We appreciate your answer, thanks for helping us.

When we add a new field as in the example:

```javascript
fields: [{ 
    field: 'expirationTimeDate', 
    type: 'Date',

```

1. Should it be added in .forestadmin-scheme.json?
2. And we could display this field in our UI layout?

If that is the case we have an issue because after adding this field scheme is not updated and we could not see it in the layout. What reasons should be to not updating the scheme? I guess this is the reason why this example didn’t solve the problem completely. We tried another way without extra fields.

We solved half of the problem, getting proper date now is working after modifying get(record) with this:

```javascript
get(record) {
    record.expirationTime = new Date(record.expirationTime * 1000);
	return record.expirationTime;
}

```

When we try the same with the set(record) we could not do the similar:

```javascript
set(record) {
	   console.log(record); // It's look like not getting here at all. Probably some syntax problem?
	   record.expirationTime = (new Date(record.expirationTime).getTime()/1000);
	   return record.expirationTime;
 },

```

still have an error:

```javascript
Data truncated for column 'expiration_time' at row 1

```

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [May 27, 2020, 3:42pm UTC](https://community.forestadmin.com/t/converting-bigint-to-datepicker/278/4 "2020-05-27T15:42:44Z")

</div>

Hi @Bojan_Antonijevic,

The `.forestadmin-schema.json` should contains a definition of your newly added field (After a server restart).  
Looking at [the smart field documentation](https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields), it seems that `set` should take more than one parameter if I’m correct.

Could you please share the complete configuration of your smart field so I could also try it myself ?

Thanks

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 19, 2021, 3:38pm UTC](https://community.forestadmin.com/t/converting-bigint-to-datepicker/278/5 "2021-04-19T15:38:52Z")

</div>

Heey @Bojan_Antonijevic,

Are you still encountering this issue. I’ll close this ticket soon if there is no reply on your part 😉
