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 8032325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:21:15+00:00 2026-06-05T01:21:15+00:00

I use the Dataset#max for a date and timestamp column ( DB[:data].max(:timestamp) , but

  • 0

I use the Dataset#max for a date and timestamp column (DB[:data].max(:timestamp),
but I get a String as result, not a timestamp or a date.

Example:

require 'sequel'
DB = Sequel.sqlite()
#~ DB.use_timestamp_timezones = true #no effect
DB.create_table(:data){
  Fixnum :num
  timestamp :timestamp
  Date :date
} unless DB.table_exists?(:data)

#Insert some testdata
1.upto(10){|i|
  DB[:data].insert(i, Time.now - 24*60*60*i, Date.today - i)
}

#
#my self written max function.
#
def max(ds,field)
    timestamp = nil
    ds.select(field).each{|ds|
      timestamp = ds[field] if ! timestamp or timestamp < ds[field]
    }
    timestamp
end


##Ok
p max(DB[:data],:num)
p DB[:data].max(:num)   #ok

p max(DB[:data],:timestamp)     #timestamp -> ok
p DB[:data].max(:timestamp)     #String!!

p max(DB[:data],:date)     #date -> ok
p DB[:data].max(:date)     #String!!

I made a crosscheck, if the data are really timestamps/dates,
this seems to be ok:

##Crosscheck:
DB[:data].each{|ds|
  puts "Error" unless ds[:timestamp].is_a?(Time)
  puts "Error" unless ds[:date].is_a?(Date)
  puts "Error" unless ds[:num].is_a?(Fixnum)
}

I could use Time#parse to get again a timestamp:

p Time.parse(DB[:data].max(:timestamp))

But I would prefer to get the maximum in the same type.

Is there a way to get the max-result as timestamp/date?

  • 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-05T01:21:16+00:00Added an answer on June 5, 2026 at 1:21 am

    No. SQLite doesn’t actually have date or timestamp types (http://www.sqlite.org/datatype3.html). The only reason you get ruby Date and Time/DateTime values for date and timestamp columns is Sequel can look at the named type of the column (the one used in the CREATE TABLE statement), and automatically convert the value SQLite stores as a string into a Date or Time/DateTime. SQLite expressions (e.g. max(column)) are not tied to columns, and therefore Sequel can not use that method for type conversion.

    In short, if you want real date/timestamp handling, use a database that actually supports date/timestamp columns. Unfortunately, unless you are using JRuby can can use H2/HSQLDB/Derby via JDBC, I don’t believe there is another embedded database library that Sequel supports that has real date/timestamp types.

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

Sidebar

Related Questions

currently I use DataSet to read data from ADO.NET SQL provider, but I read
I use dataset' Insert() method to insert data to database.Like: public void InsertData() {
I'm attempting to use the DataSet designer to create a datatable from a query.
While looping through a Dataset which code snippet should I use, should I go
I have a dataset of environmental variables I would like to use for a
Brief question What command can I use to make my DataSet refresh it's connection
use this website a lot but first time posting. My program creates a number
I wanted to see if I could make a custom data set to use
i'm getting confuse about dataset and dataview, which i either use dataset to update
Related questions: Java PriorityQueue with fixed size How do I use a PriorityQueue? get

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.