pardom-zz / ActiveAndroid

Active record style SQLite persistence for Android
http://www.activeandroid.com
4.7k stars 1.03k forks source link

How to select two dates in where clause start and end of the month #503

Open spatil063 opened 7 years ago

spatil063 commented 7 years ago

Actually i am developing the app where i required to add the amount from start of the month till end of the month.

Below find my Query which i have tried

.where("date(datetime(collectionDate / 1000 , 'unixepoch')) BETWEEN date('now','start of month') and date('now','start of month','+one month','-one day')").execute(); ..where("date(datetime(collectionDate / 1000 , 'unixepoch')) BETWEEN date('start of month') and date('now')")

Both I have tried but nothing works

Belwo find Model

@Table(name = "Collection") public class CollectionModel extends Model {

@Column(name = "userLoginId")
public String userLoginId;

@Column(name = "collectionDate")
public Date collectionDate;

@Column(name = "accountLedgerId")
public Double accountLedgerId;

// C = Cash, B = Cheque, N = Non Payment
@Column(name = "collectionStatus", length = 1)
public String collectionStatus;

@Column(name = "againstBillNo", length = 20)
public String againsBillNo;

@Column(name = "collectionAmount")
public Double collectionAmount;

@Column(name = "chequeNo")
public Integer chequeNo;

@Column(name = "chequeDated")
public Date chequeDated;

@Column(name = "nextVisit")
public Date nextVisit;

@Column(name = "prefVisitTime", length = 5)
public String prefVisitTime;

@Column(name = "nonPaymentRemark")
public String nonPaymentRemark;

}

luna-vulpo commented 7 years ago

did u solve your problem? If yes post solution, pls :)

spatil063 commented 7 years ago

no.Are r u having NY SOLUTION FOR THAT

On Mon, Mar 6, 2017 at 6:32 PM, luna-vulpo notifications@github.com wrote:

did u solve your problem? If yes post solution, pls :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pardom/ActiveAndroid/issues/503#issuecomment-284389911, or mute the thread https://github.com/notifications/unsubscribe-auth/AV33yeaoJejsH_lADoAsZpIc4udwd5ISks5rjAPYgaJpZM4K2f0d .

azizimusa commented 4 years ago

You are doing it wrongly. Please refer the basic query. It should be like this:

String s = "start of month"; String d = "end of month";

Example 1 // date after start of month .where("collectionDate > ?", s).execute()

Example 2 // select specific month only .where("collectionDate BETWEEN ? AND ?", s, d).execute()

luna-vulpo commented 4 years ago

thx. But now we rid the ActiveAndroid from project.

csr91706 commented 2 years ago

name = "timestamp", index = true) private String timestamp; timestamp is format will be work!