BSON_APPEND_DATE_TIME(3)

πŸ’… BSON_APPEND_DATE_TIME ✨

okay bestie so this is a libbson manual page, section 3, for BSON_APPEND_DATE_TIME(3) β€” the little function that slides a timestamp into your BSON doc. it's giving "small but mighty" and honestly? iconic. let's get into it πŸŽ€


✨ SYNOPSIS ✨

#define BSON_APPEND_DATE_TIME(b, key, val) \
   bson_append_date_time (b, key, (int) strlen (key), val)

bool
bson_append_date_time (bson_t *bson,
                       const char *key,
                       int key_length,
                       int64_t value);

so there's the macro version (which does the strlen() math for you, so cute of it) and the real function underneath. slay. 🫢


🌸 PARAMETERS 🌸

  • bson β€” a bson_t. that's the doc you're appending into, your canvas, your main character πŸ’–
  • key β€” an ASCII C string with the name of the field. like, the label on the box.
  • key_length β€” how long key is, in bytes. or pass -1 and it'll figure the length out with strlen() for you. lowkey convenient.
  • value β€” the date and time, expressed in milliseconds since the UNIX epoch. that's the whole vibe: a big ol' number of ms. ⏳

πŸ¦‹ DESCRIPTION πŸ¦‹

bson_append_date_time() shall append a new element to a bson document containing a date and time with no timezone information. so like, the timestamp is just a number β€” it does not come with a little "hey i'm in UTC-5" note attached. πŸ™ˆ

value is assumed to be in UTC format of milliseconds since the UNIX epoch. and here's the tea: value MAY be negative. yes bestie, you can absolutely go back in time. pre-1970 is allowed, no cap. πŸ”₯


πŸ’œ RETURNS πŸ’œ

returns true if the operation was applied successfully. πŸŽ‰

the function will fail if appending value grows bson larger than INT32_MAX. so if your doc gets too thicc, it's not happening. know your limits, periodt. πŸ’€


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” the ones who brought you the whole thing. respect. 🫑


2009-present, MongoDB, Inc. β€” all rights reserved, all vibes reserved. ✨


🧚 quick vibe check reminder: the ms-since-epoch thing is the entire personality of this function. no timezone, just milliseconds, and negative is totally fine.

and that's the whole page, bestie! this one came from libbson version 2.5.6, dated Oct 09, 2026 β€” go forth and timestamp responsibly, ily, bye πŸ’…πŸ’–πŸ“

πŸ“¦ where this page comes from