Python fraction of seconds

In the datetime module, the datetime, time, and timedelta classes all have the smallest resolution of microseconds: >>> from datetime import datetime, timedelta >>> now = datetime.now() >>> now datetime.datetime(2009, 12, 4, 23, 3, 27, 343000) >>> now.microsecond 343000 if you want to display a datetime with fractional seconds, just insert a decimal point and … Read more

to_datetime Value Error: at least that [year, month, day] must be specified Pandas

You can stack / pd.to_datetime / unstack pd.to_datetime(dte.stack()).unstack() explanation pd.to_datetime works on a string, list, or pd.Series. dte is a pd.DataFrame and is why you are having issues. dte.stack() produces a a pd.Series where all rows are stacked on top of each other. However, in this stacked form, because it is a pd.Series, I can … Read more

Pyspark: Extract date from Datetime value

Pyspark has a to_date function to extract the date from a timestamp. In your example you could create a new column with just the date by doing the following: from pyspark.sql.functions import col, to_date df = df.withColumn(‘date_only’, to_date(col(‘date_time’))) If the column you are trying to convert is a string you can set the format parameter … Read more

Parse_dates in Pandas

This is a non-standard format, so not caught by the default parser, you can pass your own: In [11]: import datetime as dt In [12]: dt.datetime.strptime(’30MAR1990′, ‘%d%b%Y’) Out[12]: datetime.datetime(1990, 3, 30, 0, 0) In [13]: parser = lambda date: pd.datetime.strptime(date, ‘%d%b%Y’) In [14]: pd.read_csv(StringIO(s), parse_dates=[0], date_parser=parser) Out[14]: date value 0 1990-03-30 140000 1 1990-06-30 30000 … Read more

How to produce localized date string with CultureInfo

You can use the second argument to the toString function and use any language/culture you need… You can use the “d” format instead of ToShortDateString according to MSDN… So basically something like this to return as Australian English: CultureInfo enAU = new CultureInfo(“en-AU”); dt.ToString(“d”, enAU); you could modify your method to include the language and … Read more

MySQL query for current GMT time

Just use UTC (doesnt get affected with daylight savings time) SELECT UTC_TIMESTAMP(); Old Content for reference: this should work, but with SELECT CONVERT_TZ(NOW(),’PST’,’GMT’); i got also NULL as result. funny enough the example in the mysql docu also returns null SELECT CONVERT_TZ(‘2004-01-01 12:00:00′,’GMT’,’MET’); http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_convert-tz seems you found a bug in mysql. (thanks to +Stephen Pritchard) … Read more

How to display current year in Flask template?

Use a template context processor to pass the current date to every template, then render its year attribute. from datetime import datetime @app.context_processor def inject_now(): return {‘now’: datetime.utcnow()} {{ now.year }} Or pass the object with render if you don’t need it in most templates. return render_template(‘show.html’, now=datetime.utcnow())

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)