How to store Indian date and Time in MongoDB ? and How to query using Time fileds(HH:MM:SS) - mongodb

What is the best way to store indian date and time in mongodb?
I'm going to upload bill details in mongodb. So i've to capture the Bill time which is printed in Bill. This will be in the format like '2014-12-22 14:10:25'. ISODate is good solution? How to covert above date value into ISODate format? Is there any default fuction avilable in mongodb?
How to query the documents based on time elements.For example hourly wise document search.
Please advice

that is possible through JavaScript's Date objec, that supports the ISO date format, so as long as you have access to the date string, you can do something like this:
> doo = new Date("2012-07-14T01:00:00+01:00")
Sat, 14 Jul 2012 00:00:00 GMT
> doo.toTimeString()
'17:00:00 GMT-0700 (MST)'
If you want the time string without the seconds and the time zone then you can call the getHours() and getMinutes() methods on the Date object and format the time yourself.
if any problem please comment me..)

Related

Turning a localized Date to a Timestamp in Firebase

I'm new to Firestore and since it doesn't seem like it has a native createdAt/updatedAt as part of a document, I'm creating them when I create the new document. Using a straight up Date() as the value for my initial dictionary that I save to Firestore obviously gives me a localized date/time – UTC -500, for example.
Firestore stores this as November 19, 2018 at 5:14:54 PM UTC-5
Is there a specific date format that Firestore likes in order to save something as a Timestamp and so that I will be able to sort on it later?
I tried using "yyyy-MM-dd HH:mm:ss Z" as the dateFormat from just printing out the value of Date() in a Playground. Would love some help here. Thanks!
A Timestamp object doesn't have a date format. It's just a measurement of a number of seconds since Unix epoch, plus some number of nanoseconds. It does not accept a formatted time. If you have a formatted time, you will have to parse it to get a Timestamp object in return.`
The date format you're seeing in the console is just the way the console is choosing to format it. If you want to format a Timestamp for display, you'll need to do that yourself.

Convert Exif date to different format

I am getting an exif date value like
EXIFPhotoDate: 1506173228000 and
UploadDate: 1506485214000
but I know it is
EXIFPhotoDate 23/9/2017, 23:27 and
UploadDate 9/27/2017, 01:59
The former is when queried via REST and the latter is when queried via the table.
How can I get standard date/time from a value like this?
Looks like you have a number of milliseconds since January 01 1970 in UTC. If you remove the 000 from the end, you will have a Unix timestamp, that is, the number of seconds since January 01 1970 in UTC:
unixTimestamp = 1506173228000 / 1000
Once your question doesn't state any programming language, it's hard to give you further help.

Store/Index time in mongo, use a timestamp or a date/time

When storing a timestamp in mongodb should I store the 'unix-time' millis since some date or should I store an actual date/time?
What are the benefits of either?
Edit
To be more specific should I store a long that is seconds since Jan 1. 1970, or should I store a Javascript date object.
I recommend using the MongoDB native date format. The advantage of that is that you can then easily use the date operators:
http://docs.mongodb.org/manual/reference/operator/aggregation-date/

to store date in mongodb

I need to store date in mysql (without time). User inputs date in input box like yyyy-mm-dd, may be later fomat could change.
Could you please tell what is good way to store date in mongodb (without time), we'd use DATE type in mysql? Now whe I need to store date and time I use mongdb date type.
And store it like this:
$data['ADDED'] = new MongoDate(time());
And display them:
echo gmdate('Y-m-d H:i:s', $data['ADDED']->sec);
When I use only date I store them as string like: yyyy-mm-dd (I validate date before storing it to make sure it's correct date). I'll need to find by date something like this:
dateField <(>) somedate
Do you think it's acceptable to store date as string in mongodb? How do you usually store date in mongodb?
MongoDB does not have a DATE type. It instead has a ISODate type. This is just as good for storing "without" time as I will explain.
So you can use MongoDate like so:
$date = new MongoDate(); // Denotes today, just like the date() function
Now to store without time you can just fake it by making PHP only set a date, as such the default time will be 00:00:00 (I should note this does mean a time is actually stored just as 00:00:00):
$date = new MongoDate(strtotime('2012-04-23')); // strtotime for fun
And then you can query by just the date part like:
find(array('date' => new MongoDate(strtotime('2012-04-23'))));
And you can now query as though you don't have a time since the time will equal what you put in: 00:00:00.
Of course this is just one way of fixing it.

Date and timezone using j2me

I have a date string as input from an rss like:
Wed, 23 Dec 2009 13:30:14 GMT
I want to fetch only the time-part, but it should be correct according to the my timezone. Ie, in Sweden the output should be:
14:30:14
What is the best way? I want it to work with other RSS date formats as well if possible. Im using regexp right now but that is not very general.
Im having a hard time finding any library or support for dates and timezones in j2me?
/Br Johannes
In normal Java, I'd use a SimpleDateFormat object (that you create to match the pattern of the date you're getting in the RSS) to parse the String value and give you a Date object. Then, using a Calendar (which would be localized to your time zone), you'd be able to get the hour, minute, and second information.
I don't know j2me, but a google search suggests that these classes are available in j2me.