Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:01:30+00:00 2026-06-10T05:01:30+00:00

I have the following query: users = Analytics.objects.values(‘date’, ‘users’).order_by(‘date’) [(datetime.date(2012, 8, 20), 156L), (datetime.date(2012,

  • 0

I have the following query:

users = Analytics.objects.values('date', 'users').order_by('date')
[(datetime.date(2012, 8, 20), 156L), (datetime.date(2012, 8, 21), 153L),...]

How would I get the unix timestamp of the datetime here? The equivalent of doing:

select concat(UNIX_TIMESTAMP(date), '000') as date, users from analytics_analytics
1345446000000   156
1345532400000   153
1345618800000   153

Note that I do not want to do formatting in python as there are a lot of the above calls that need to be done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:01:31+00:00Added an answer on June 10, 2026 at 5:01 am

    The best way to do this, if really want the DB to do the conversion (and this can be applicable for other things, in general when you want to return information that’s not readily available in a column from the DB), you can use the QuerySet.extra() function https://docs.djangoproject.com/en/dev/ref/models/querysets/#extra like this:

    Analytics.objects.extra(select={'timestamp': "CONCAT(UNIX_TIMESTAMP(date), '000')"}).order_by('date').values('timestamp', 'users')
    

    Downside of this is that it’s no longer DB agnostic, so when you change RDBMS, you have to change the code. Upside is you can use values with it, unlike a property on the model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Query : INSERT INTO users (user_id, date_created) VALUES (?,?) I
I have the following query to select users and their locations, etc from MySQL
I have the following query that retrieve the number of users per country; SELECT
I have the following Rails Query: Org.find(:all).each do |org| Org.update_counters org.id, :users_count => org.users.length
I have the following query: $sql = UPDATE db.users SET $str WHERE users.{$this->row} =
I have the following query: $usersTable = new Users(); $rowset = $usersTable->select() ->setIntegrityCheck(false) ->where(
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following result from the following query: SELECT users.ID, user_registered, post_date, post_type
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have following query: Article.joins(:themes => [:users]).where([articles.user_id != ?, current_user.id]).order(Random()).limit(15).uniq and gives me the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.