There are 2 parameters like t_date and date_format on create record request.
eg. t_date = "2021-05-15" and date_format="yyyy-mm-dd"
NOTE: date_format can be different in different requests.
I want to save date in t_date field as per format given in date_format field.
how can I write below create query for above problem?
obj = Object.create(t_date: ?)
Trying to save record with date value as per given format in parameters.
while saving dates, and times and datetime objects we need to save directly(like all other fields). we need not to menction the format in which it needs to be saved while saving to database. in views we need to use some view helpers . if we use those view helper by passing format as argument to those view helper methods. it will display as per our menctioned format.
There are some datatimes methods like for example below.
User.created_at.strftime("pass the format here")
its vary bad idea to save format of the date or time. in case if user want the option to select the date or time or datetime as per his format then, add a column to user table like format and while displaying the dates and times fetch the user selected format and pass this as argument to the view helper methods. saving format for every request to database is a very bad database design.
Times also we should not save the times by converting into various time zones. we should save the times as it is(by default it saves in UTC time) while displaying the times from database we need to display in what ever the timezone he is in. you should maintain a column like timezone to save the users timezone and while displaying you need to pass this timezone as argument to view helper methods
How can I set the date is -2 by default when opening the workbook(due to data base delay , set to -2 days can have the full data),
also I still need the regular date filter working so users can then change to anyother dates
I have tried create a calculated field with the formula TODAY()-2 and then apply to a parameter, (set as when worksbooks opening), but still not working.
Thanks
I've created a parameter with values 1970-2013 range and have then created calculated field with the below code
[Year] = [parameter year]
If you only want to filter by year, then you don’t need a parameter or a calculated field. Just put the Year field on the filter shelf and show the filter control.
A parameter is useful in other circumstances, say if you want to treat one year differently, but keep all years in the viz
In Calculation field don't use " = "sign, just type parameter name only and click 'OK'.
I can already change the value of a destination DateTime field by assigning it e.g. 2000-01-01 00:00. But if either of the systems changes their timezone, this value will also change with them, so I cannot rely on it always keeping this value.
So, is there a way to clear the value of the column?
If we do not type or insert a value, Zapier assumes that we do not want to update it.
I want to let users specify a date that may or may not include a day and month (but will have at least the year.) The problem is when it is stored as a datetime in the DB; the missing day/month will be saved as default values and I'll lose the original format and meaning of the date.
My idea was to store the real format in a column as a string in addition to the datetime column. Then I could use the string column whenever I have to display the date and the datetime for everything else. The downside is an extra column for every date column in the table I want to display, and printing localized dates won't be as easy since I can't rely on the datetime value... I'll probably have to parse the string.
I'm hoping I've overlooked something and there might be an easier way.
(Note I'm using Rails if it matters for a solution.)
As proposed by Jhenzie, create a bitmask to show which parts of the date have been specified. 1 = Year, 2 = Month, 4 = Day, 8 = Hour (if you decide to get more specific) and then store that into another field.
The only way that I could think of doing it without requiring extra columns in your table would be to use jhenzie's method of using a bitmask, and then store that bitmask into the seconds part of your datetime column.
in your model only pay attention to the parts you care about. So you can store the entire date in your db, but you coalesce it before displaying it to the user.
The additional column could simple be used for specifying what part of the date time has been specified
1 = day
2 = month
4 = year
so 3 is day and month, 6 is month and year, 7 is all three. its a simple int at that point
If you store a string, don't partially reinvent ISO 8601 standard which covers the case you describe and more:
http://en.wikipedia.org/wiki/ISO_8601
Is it really necessary to store it as a datetime at all ? If not stored it as a string 2008 or 2008-8 or 2008-8-1 - split the string on hyphens when you pull it out and you're able to establish how specific the original input was
I'd probably store the datetime and an additional "precision" column to determine how to output it. For output, the precision column can map to a column that contains the corresponding formatting string ("YYYY-mm", etc) or it can contain the formatting string itself.
I don't know a lot about DB design, but I think a clean way to do it would be with boolean columns indicating if the user has input month and day (one column for each). Then, to save the given date, you would:
Store the date that the user input in a datetime column;
Set the boolean month column if the user has picked a month;
Set the boolean day column if the user has picked a day.
This way you know which parts of the datetime you can trust (i.e. what was input by the user).
Edit: it also would be much easier to understand than having an int field with cryptic values!
The informix database has this facility. When you define a date field you also specify a mask of the desired time & date attributes. Only these fields count when doing comparisons.
With varying levels of specificity, your best bet is to store them as simple nullable ints. Year, Month, Day. You can encapsulate the display logic in your presentation model or a Value Object in your domain.
Built-in time types represent an instant in time. You can use the built in types and create a column for precision (Year, Month, Day, Hour, Etc.) or you can create your own date structure and use nulls (or another invalid value) for empty portions.
For ruby at least - you could use this gem - partial-date
https://github.com/58bits/partial-date