Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to insert date in ActiveRecord ! #524

Open
deshario opened this issue Jul 2, 2017 · 1 comment
Open

How to insert date in ActiveRecord ! #524

deshario opened this issue Jul 2, 2017 · 1 comment

Comments

@deshario
Copy link

deshario commented Jul 2, 2017

@column(name = "timestamp", index = true)
private Date timestamp;

Or

@column(name = "created_at")
private String created_at;

Should i use String or Date .... Can i have example of how to insert date into sqlite properly ! Thankyou

@naXa777
Copy link

naXa777 commented Jul 2, 2017

ActiveAndroid supports serializing Date fields automatically. It is stored internally as a timestamp (INTEGER) in milliseconds.

@Column(name = "timestamp", index = true)
private Date timestamp; 

Create a Util method to convert String to Date, if you want:

public Date getDateFromString(String selectedDate) throws ParseException{
    DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
    Date date = format.parse(selectedDate);
    return date;
}

ps. ActiveAndroid has a pretty strong community on Stack Overflow, so you're welcome to ask your questions there. Actually this answer is copied from the Stack Overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants