Can Pandas (or Python) recognize today's date? - 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’)

Related

AnyLogic Date format

Is there a way to change the date format in AnyLogic, without constructing something with the implemented Time functions?
I want my Date to be displayed in such a way
"E dd.MM.yyyy HH:mm"
With the timefunctions I have problems, to get the date into the right format
Not sure what that E stands for, but if it's the timezone, you can get it with this:
ZoneId.of("Europe/Oslo").getDisplayName(TextStyle.SHORT_STANDALONE, Locale.ENGLISH)
I used Europe/Oslo there, but you can find the zone ids that you need here:
https://docs.oracle.com/middleware/12211/wcs/tag-ref/MISC/TimeZones.html
to use this you need to import libraries in Main/Advanced Java/Imports section
import java.time.ZoneId;
import java.time.format.TextStyle;
And then to get the required code with that format:
"E "+String.format("%02d", getDayOfMonth())+"."
+String.format("%02d",getMonth()+1)+"."
+String.format("%04d",getYear())+" "
+String.format("%02d",getHourOfDay())+":"
+String.format("%02d",getMinute())
You can replace the "E " with what I explained before
Or you can use whatever is currently your timezone... AnyLogic uses your computer timezone in order to know what timezone you are in:
Calendar cal=Calendar.getInstance();
cal.setTime(date());
String timezoneCode=cal.getTimeZone().toZoneId().getDisplayName(TextStyle.SHORT_STANDALONE, Locale.ENGLISH);

Spark Scala script to read data from S3 on daily basis

There is one java application which dump data(in csv file) to s3 on daily basis. This application create folder in S3 based on system date like(MM-DD-YYYY format) and then add files to the folder created.
Now i want to read those files from S3 on daily basis like
val fileFromS3= sc.textFile("s3a://digital/MM-DD-YYYY/abc.csv")
Now the script should replace 'MM-DD-YYYY' with the system date.
Please suggest possible solution or any other way to achieve this.
You can get currentTime with Calendar class.
First you need some imports:
import java.util.Calendar
import java.text.SimpleDateFormat
import java.util.Date
Then you can get the current Time:
val now = Calendar.getInstance().getTime()
And prepare the formatter the retrieve the date in the proper format you want and to ensure double digit month and days
val formatter = new SimpleDateFormat("MM-dd-yyyy")
Then you can use your formatter to get the date as String
val dateAsString = formatter.format(now)
Then you can load your resource with the dateAsString value using String interpolation:
edit to remove typo:
val fileFromS3= sc.textFile(s"s3a://digital/${dateAsString}/abc.csv")

Changing the default date format in classic asp when using the "date" function

I'm migrating a whole bunch of web pages that were written in classic asp over to a new server, and have discovered many references to the simple date() function, like:
if cint(left(date,instr(date,"/")-1)) < 9 then blah blah
I'm getting errors because the new server's default date format is returning yyyy-mm-dd, and the code above is expecting it to be in dd/mm/yyyy format.
Rather than manually fixing every occurrence, of which there could be hundreds, I'm looking to see if I can change the default date format for asp so that date() returns dd/mm/yyyy. I thought by simply changing the system's short date format would do the trick, but even after restarting the server it's still showing yyyy-mm-dd.
Is there a setting somewhere where you can specify the default date format when using the date() function?
This worked for me:
change global.asa, in the Sub Session_OnStart, add a line
Session.LCID=1033

What format is required to import a date into google spreadsheet

With the help of "stackoverflow" and it's users I'm using an app to import data into a Google spreadsheet. The problem is I have a date question on the form, and can not manage to import it. If I change the format (in the forms) to text, the data imports as it has been sent from the app, but when I change it back to date, nothing.
I've believe I've tried all the usual date formats (dd/mm/yyyy, mm/dd/yyyy, yyyy/mm/dd, yyyy/dd/mm) as well as yy for the above and also numerical.
I know that the Google form shows the date in the users format and that is not a problem. It shows up correctly in the spreadsheet in my local format (dd/mm/yyyy).
Does anyone know what format the form uses to send the data to the spreadsheet, or anyway to find out.
Thanks in advance.
Ok, after using wikipedia, and trying every different format it works by using the format yyyy-mm-dd

Converting a string timestamp to Date results in reset to UNIX epoch

I'm having some problems converting a string to a date object in google apps script.
My dates are in the following format, from a 3rd party API:
2013-01-17T17:34:50.507
I am attempting to convert this to a Date object:
return Date(stringDate);
And this is being returned:
Thu Jan 01 01:00:00 GMT+01:00 1970
Can someone tell me what i'm doing wrong, and how to resolve this issue ?
With moment.js, it is as easy as this to parse any of ISO 8601 format.
var date = Moment.moment("2013-01-17T17:34:50.507").toDate();
You can use moment.js to parse your arbitrary date string as well.
To use moment.js in GAS, you just need to add it in the script editor.
Open your script in GAS script editor and go to "Resources" then "Libraries...", then put this project key MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48 and click "Add". Choose the version from the dropdown, then click "Save". Now, you are ready to use moment.js in GAS.
moment.js can be used to parse date string, create formatted date string, and many other date manipulation. Thanks to the author!
You can find the moment.js documentation here.
It doesn't appear that the Date object knows how to handle that date. The date is in ISO 8601 format. Javascript can handle Dates if they are given timezone information.
You will have to do some testing, but if those dates given to you are in UTC time, then just add a Z to the end of the date string before you call new Date().
Edit: The Apps Script Date object can't seem to handle a timezone other than UTC when parsing a Date. I opened an issue for it.
It doesn't work in GScript, at least for me at the time I'm writing it.
This post serves a working alternative: How do I format this date string so that google scripts recognizes it?
As of now new Date() seems to work:
var dT = new Date("2013-01-17T17:34:50.507");
console.info("dT: %s or %d", dT, dT.getTime());
returns dT: Thu Jan 17 17:34:50 GMT+01:00 2013 or 1.358440490507E12 in Google Apps Script