1

Hi my Schmema has a field with an ISO-Date:

ISODate("2015-04-30T14:47:46.501Z")

Paypal returns on a successful payment a date object in that form:

Time/Date stamp generated by PayPal, in the following format: HH:MM:SS Mmm DD, YYYY PDT
Length: 28 characters

Now I want to update the database entry which has the payers_email_address and a timestamp which does maximum differ from paypals timestamp by 15min.

These are the steps I think are necessary to do this:

1) On this step I'm not sure. The blunt way would be to Stringify the paypal date and then to split it and rearrange it. But I guess there is a better way?

Question: How to convert the PDT date properly into the UTC date.

2) Make a new UTC date: var dt = new Date('2010-06-09T15:20:00Z');

3) Add 15 min to the date: dt.setMinutes (dt.getMinutes() + 15);

4) Query inbetween two dates MongoDB/Mongoose querying at a specific date?

In whole (does not work for a date on 30/04/2015)

MyModel.find({date: {"$gte": new Date("10:00:46 04 29, 2015").toUTCString(), "$lt": new Date("14:00:46 05 01, 2015").toUTCString()}})

EDIT:

I guess if I got the query bove working I can just use the same with PDT:

new Date("20:15:10 05 10, 1985 PDT").toUTCString()

I posted my steps because maybe there is mongoose function for converting the date and I don't have to do 1-3.

Community
  • 1
  • 1
Andi Giga
  • 3,744
  • 9
  • 38
  • 68

1 Answers1

1

This works in my mongoShell I will report later if it worked in the program:

MyModel.find({date: {"$gte": new Date("10:00:46 04 29, 2015 PDT"), "$lt": new Date("14:00:46 05 01, 2015 PDT")}})
Andi Giga
  • 3,744
  • 9
  • 38
  • 68