0

I'm using IBM's Cloudant (CouchDB) data store. I'm planning on storing dates as integers in the format YYYYMMDD instead of JavaScript Dates. Is there any CouchDB functionality that I'd be missing out on by not storing them as JavaScript Dates? Any other reason I shouldn't do this?

I've read this SO Q&A: What's the best way to store datetimes (timestamps) in CouchDB? and from that there appears to be no objections to storing dates in any format. It doesn't answer what built-in functionality might be lost.

Community
  • 1
  • 1
Guy
  • 65,082
  • 97
  • 254
  • 325

2 Answers2

2

You wouldn't be losing any functionality as you would make the date useful by processing it in a Map function as either a Secondary Index/View, Search Index or part of Cloudant Query.

The only downside is that by formatting them as such, you make it more difficult on yourself to use the JavaScript Date functions to modify the date to needs within a Map function.

ukmadlz
  • 151
  • 4
  • So, for example, if I wanted the year component then I'd have to `Math.round(date/10000)` instead of `date.getYear() + 1900` - is that what you mean? – Guy Oct 27 '15 at 19:05
  • Yes, or you could use `substring()`, or a regex to parse out the portions. They're all valid when in your use case. – ukmadlz Oct 28 '15 at 11:20
0

Storing it as a String is an option. Might be easier to handle this way than as an Integer.

Sora
  • 409
  • 5
  • 6
  • How would String handling be easier than Integer? Can you give an example? – Guy Jan 07 '16 at 22:02
  • You can still store it in any Date/TimeStamp format you want .You wont be loosing any information . – Sora Jan 07 '16 at 22:10