Time series in panda - javascript

How do I convert a date index into Time-based indexing?
so that i can later generate a month, weekday and a year
I tried this code
df['TRANS_DATE'] = pd.to_datetime(df['TRANS_DATE'], format='%m/%d/%Y %H:%M:%S')
but after I change it to Index the date revert back to show as object

What happens if you leave out the format option (letting it run to Default)? Also, it would be best if you show your original data.
Additional information -
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html

Related

firebase javascript compare timesamp by seconds

I have a firebase database with some dates written down in what I think is the seconds format.
I need to check if a day has passed since that date.
admin.firestore.Timestamp.now()._seconds;
is what I am using to get the current date.
I now need to compare it, but I cannot find how to add a day to the date in the firebase, and am not sure if simply using < will compare them properly.
1633399860000 <-- (database date sample)
Thank you!
So...
First of all the date format was milliseconds.
It seems like it is not a problem to compare dates with a < or >.
To add a day I tried to remove 86400000 (milliseconds) to today's date.
The code is not giving problems for now so I'm guessing it is the right solution.

Having trouble wrapping my head around how to handle dates

I'm working on a scheduling system for music venues. The basic idea is that there's an "Create new schedule" page, on which there is a DatePicker calendar (using AngularUI Bootstrap). The user selects a Date, then adds performers into timeslots. The built object looks something like this:
{
date: 2017-6-22 00:00:00.000-5:00
venue: VenueID
performances: [
{
performer: performerID,
time: 2017-06-22 22:00:23.231-5:00
},{
perfomer: performer2ID,
time: 2017-06-22 23:00:42.523-5:00
}
]
}
There's a couple of problems here. For the original date selection, I set the time (using myDate.setHours(0,0,0,0)) to midnight because the time doesn't really matter, I only care about the actual date. Likewise for the timeslots, their date doesn't matter (since they belong to the schedule for that day), so I only care about the time. Then in another project, we have a node/mongo app that saves these schedules, and returns them to a page in the angular project that lets you select a schedule for editing/etc. It selects which ones to return by grabbing all the schedules for a specific venue, and doing "if (schedule.date >= new Date().setHours(0,0,0,0)) { add schedule to return list }"
Anyway, on to the actual problem. The angular app does all of the date calculations client side. What I mean is, I'm in CST. If I select a Date on the calendar and save a schedule for that date, then someone in EST selects the same day on the calendar and saves a schedule, they have different dates in the database. For example, when I make the schedule, the date in the DB is "2017-06-22 00:00:00.000-5:00". When the EST friend makes a schedule on the same date, it gets saved as "2017-06-22 00:00:00.000-4:00".
In the "Select a schedule to view/edit" page, I do something like this:
<select ng-model="schedule" ng-options="s.date|date:'fullDate' for s in schedules" ng-show="schedules.length>=1"></select>
Of course this doesn't work because when my EST friend looks at the list, he sees the correct date. But when I look at one that he created, the date is one day off because "2017-06-22 00:00:00.000-4:00" converted to local timezone is "2017-06-21 23:00:00.000-5:00".
I guess TL;DR is I'm not sure how to handle it since the venue and anyone creating/editing the schedules may not share the same time zone. I want all of the dates/times to show up in the timezone of the venue (which I have the address for. I guess I could geolocate to find timezone?). I'm just not sure how to go about it.
The DatePicker gives you a date object. Instead of storing the entire value string just grab the day month and year Date(value).getYear() + '-' + Date(value).getMonth() + '-' + Date(value).getDate(). As for the times do the same as the dates. Store those values in the DB and then when you get them back you will have to convert them back to a date object so that the date picker can understand them.
Ultimately with this solution your just trying to store dates without the timezones. Make sure to state in your app that the times are for those areas.
You have to distinguish between the format the date/time is transported, saved vs. how the date will be shown to the user.
For transportation and saving use UTC in a format that is easy computable (eg. ISO8601).
For visualization to the user convert this value to the timezone and desired user format by using some helper library.

Convert hour to date time without adding +1

Hi im using moment js to convert this string 20:00 I tried:
var a = moment("20:00", "HH:mm")
console.log(a.format()) // 2016-09-08T20:00:00+01:00
the problem when I store in mongodb it become
2016-09-10T19:00:00.000Z
I want to store 2016-09-10T20:00:00.000Z
anyway can explain why please ?
When you say that you want to store 2016-09-10T20:00:00.000Z what you are saying is that you want to assume that your date and time is UTC.
To assume that the date you are parsing is a UTC value, use moment.utc
var a = moment.utc("20:00", "HH:mm")
console.log(a.format()) // 2016-09-08T20:00:00Z
Note that when you parse a time without a date, moment assumes the current date. This may not be the behavior that you want.
I'm also not sure if you want a UTC date (which is what you are saying), or a local date without an offset indicator. If you want a local date without an offset indicator, simply use a format without an offset:
moment.utc("20:00", "HH:mm").format('YYYY-MM-DDTHH:mm:ss.SSS')
"2016-09-08T20:00:00.000"
If you are dealing with local dates that do not have a time zone association, I recommend using moment.utc to parse, as this will ensure that the time does not get shifted to account for DST in the current time zone.
For more information about how to parse dates into the time zone or offset that you would like in moment, see my blog post on the subject.
This it how it should look:
var a = moment("20:00", "HH:mm")
console.log(a.utcOffset('+0000').format())
<script src="http://momentjs.com/downloads/moment.min.js"></script>
Doe, the problem is that you are using timezones when you create the date.
MomentJS uses your current timezone automatically.
Mongo however saves the time as it would be in another timezone.
Therefore, if you want the two strings to format the same way, you need to set the timezone.

Subscrate Dates and convert to the Format DD:HH:MM:SS Left

I am facing a problem where I need to add seconds to a date and then subtract the current date to get the remaining time for the update to be completed.
I can use a hidden input to get the value from the database using jQuery. I would therefore have a hidden input with the value of create_at date, under the format 2015-09-10 14:44:24 UTC and a hidden input with the time in seconds ex: 86400 => 1Day the update takes to be completed.
How can I, using rails, jQuery & js to get the value under the format D:HH:MM:SS left for to update to be completed.
Concrete Question: How can I add 86340 seconds to the 2015-09-10 14:44:24 UTC to get a new date (update finish time) and then get the current time at UTC and "subtract" that from the update finish time to get the time left for the update to finish and then convert that to the format DD:HH:MM:SS.
Let me know if I am not clear enough. Thank you.
moment.js to the rescue
http://momentjs.com/
var dateString = moment('2015-09-10 14:44:24 UTC')
.add(86400, 's')
.format('DD:HH:MM:SS');
// hope i understood your request correctly
moment has a bunch of helpful methods for manipulating dates.
alternatively you can convert all dates to ms and manipulate them as integers.

Format Date and Time into DTG

I have a row where users enter in various type of data in the date in there are different formats that I want to standardize. For example
12/21/2014 1900
This is one possible format I would like for the <td> to change it into DTG format which is
DD-HHMMZ-MMM-YY
Day, Hours in 24 format, Minutes, instead of p.m./a.m. I need Z for zulu, Month and year
How do I have this change once the user enters the data? I was looking at the onchange for javascript but I am not completely sure.
I'm assuming what you're asking is how to force the input to update after the user enters the date information. I'm assuming you know how you're going to format the date based on the given input.
This example shows you how to use jquery's .change() to update the input after something is entered. http://jsfiddle.net/Z5B25/
The basic code looks like:
$('.date').change(function(){
$(this).val('Computed/formatted Date');
});
Though this is not specific to your usage.

Categories

Resources