Date Manipulation as a string in python 2.7 - date

I am new to Python.I would like to know how I can manipulate a string that contains the date. For example, I want to transform today's date to the first day of the next year.
For example:
07/02/2018 --> 01/01/2019
How is that possible in Python 2.7?

You can use datetime package from python. Convert your string in to a date and do the manipulations. See more at here.
https://docs.python.org/2/library/datetime.html

Related

Flutter: Display local datetimes correctly

let's say I have a DateTime object and I want to display it in the correct local format.
If I do the following on a German device I get this:
dateTime.toLocal().toString()
// Prints
2022-05-28 23:29:19.518
However, I would expect or desire more something like this for a German device: 28.5.2022 23:29:19
I know that I can format the DateTime but that would just be hardcoding it for a certain locale.
Weirdly enough all the solutions that I found for this on StackOverflow are either hardcoding the format or only apply to Dart, not Flutter.
What is the correct way to display a local datetime in Flutter?
You can use this package intl and localise dates like
var format = DateFormat.yMd('ar');
var dateString = format.format(DateTime.now());
Using the intl package which was mentioned here already, this has been working well for me so far:
DateFormat dateTimeFormat = DateFormat.jm(Localizations.localeOf(context).toString());
DateTime dt = DateTime.fromMicrosecondsSinceEpoch(entity.syncDateTime);
dateTimeFormat.format(dt);
To get outputs which are not yet supported I, for example, concat a ymd formatted DateTime string with a jm formatted DateTime string.

Format string date into date object

I have a date in this format: December 5th 2017. How do I convert it to either a timestamp or a date object?
I tried the following but it return NaN:
let tDate = new Date('December 5th 2017')
use a library like moment.js (momentjs.com) to parse custom date formats into Dates. As of version 2.13 it apparently comes with typings out of the box and can therefore be used easily with TypeScript (aureliajsrocks.com/moment-js-now-typescript-compatbile)

Can Pandas (or Python) recognize today's date?

I was wondering if Pandas can somehow figure out what today's date is allowing me to automate the naming of the html file I create when I use the "df.to_html" method.
Basically I"m trying to read a website using method "pd.read_html", and then save the dataframe as an html file, daily. The name of the html file will be the day's date. (So today is 9/28/2016 and tomorrow will be 10/01/16 and so on ) I'm not particular about the format of the date, so Sept or 09, whichever is okay.
I'm trying to automate this as much as possible, and so far the best I've gotten is, using ".format" which allows me some flexiblity. But I don't know how I can further automate the process.
import pandas as pd
df = pd.read_html('random site')
today_date = 'saved data/{}.html'.format('Sept 28') # I'm saving it in the folder "saved data" with the name as today's date.html.
df.to_html(today_date)
Thanks.
See the datetime module.
specifically: datetime.date.today().isoformat() gives you a string with the current date in ISO 8601 format (‘YYYY-MM-DD’)

Format date and add month to it

I'm currently working with embarcadero c++, this is the first time I'm working with it so it's completely new to me.
What I'm trying to achieve is to get the current date, make sure the date has the "dd/MM/yyyy" format. When I'm sure this is the case I want to add a month to the current date.
So let's say the current date is 08/18/2016 this has to be changed to 18/08/2016 and then the end result should be 18/09/2016.
I've found that there is a method for this in embarcardero however I'm not sure how to use this.
currently I've only been able to get the current date like this.
TDateTime currentDate = Date();
I hope someone will be able to help me out here.
I figured it out.
After I've searched some more I found the way to use the IncMonth method on this page.
The example given my problem is as follows:
void __fastcall TForm1::edtMonthsExit(TObject *Sender)
{
TDateTime StartDate = edtStartDate->Text;
int Months = edtMonths->Text.ToInt();
TDateTime NextPeriod = IncMonth(StartDate, Months);
edtNextPeriod->Text = NextPeriod;
}
After looking at I changed my code accordingly to this
TDateTime CurrentDate = Date();
TDateTime EndDate = IncMonth(CurrentDate, 1);
A date object doesn't have a format like "dd/MM/yyyy". A date object is internally simply represented as a number (or possibly some other form of representation that really isn't your problem or responsibility).
So you don't have to check if it's in this format because no date objects will ever be in this format, they simply don't have a format.
You will have to do additions/subtractions on the Date object that the language or library gives you, THEN (optionally) you can format it to a human-readable string so it looks like 18/08/2016 or 18th of August 2016 or whatever other readable format that you choose.
It might be that the TRANSFER of a date between 2 systems is in a similar format, but then formatting the date like that is entirely up to you.
As for how to do that, the link you posted seems like a possible way (or alternatively http://docwiki.embarcadero.com/Libraries/Berlin/en/System.SysUtils.IncMonth), I'm afraid I can't give you an example as I'm not familiar with the tool/language involved, I'm just speaking generically about Date manipulations and they should ALWAYS be on the raw object.

How do I convert date and time from the jPlaton format to the international standard date and time notation?

I am using the jPlaton platform and I have a PlatonScript record that contains a date and a time field.
The date field is a integer like 20140526.
I want to convert it to a YYYY-MM-DD string. That it: 20140526 --> "2014-05-26"
The time field is a integer like 90903417.
I want to convert it to an HH:mm:ss string. That it: 90903417 --> "09:09:03"
Any ideas?
Thanks
The basic functions you need are:
ASDATE (for integer to string transformation)
example: #s_dateFromInteger# = (ASDATE:YYYY-MM-DD) #s_integerDate#
ASTIME (for long to string transformation)
example: #s_timeFromLong# = (ASTIME:HH:mm:ss) #s_longTime#
In these examples #s_dateFromInteger# and #s_timeFromLong# are the Strings you require.
s_integerDate is the classic integer date representation used by jPlaton (yyyyddmm).
s_longTime is the classic long time representation used by the platform (hhmmssSSS)
Don't forget that the date and time patterns used by Platonscript are the usual JAVA patterns, since Platonscript interpreter returns pure JAVA