I'm trying to get the difference between the 2 dates in googlescript. However it doesn't seem to be working. Does anyone seem to know why? My user defined variables are working it's just when i get the difference between the 2 the result is like 4.28E8 whereas the answer is supposed to be like 40. Is there a way to convert the date into a number then convert it back into a date?
ddate = output.getRange(lRow2,2,1,1).getValue() - output.getRange(2,1,1,1).getValue()
Function works, its just the difference is in milliseconds. For those interested in the conversion, it's as follows:
diff = ((output.getRange(lRow2,2,1,1).getValue() - output.getRange(2,1,1,1).getValue()) / (1000*60*60*24))
or simply:
days = milliseconds/ (1000*60*60*24)
Related
I'm trying to multiplay a field of type time. Sometimes it works and sometimes it doesn't. This is in phpmyadmin with MySQL.
Things I have tried already:
I have tried googling 'sql multiplying time type returns 00:00:00'
but have no luck with that or similar searches.
I ran a python script that pulled all these times and multiplied them
by 6 and 11 and all of them worked - there were no 00:00:00.
I have also tried doing it individually on a row, and it didn't work
for the same ones.
Below are pictures before and after I run this query:
UPDATE journeys, travel_type
SET journeys.jo_duration = journeys.jo_duration * travel_type.tt_duration_multiplier
WHERE journeys.jo_type = travel_type.tt_id
I get no errors.
Some probably helpful information:
Type 1 means 11 - so I want the value in jo_duration to be multiplied by 11. Type 3 means 6 (same principle). 2 means 1 (so nothing changes).
There are more rows in this table that have this problem but I didn't want to screenshot the whole table. I thought this should be enough. There are 70 total rows. When I run the above query it says '47 rows affected' (when all rows should technically be affected I think?). I'm not sure if the remaining aren't affected because they're type 2 or if they're the ones being turned to 00:00:00 (or both)?
If you need more information, feel free to ask!
As you can see below, rows with jo_id; 1, 3, 4, 6 are 00:00:00. But others multiply correctly?
Does anyone know why this is? And how I can prevent it?
Sorry for the long post and I hope my problem has made sense!
Thank you!
Before:
After:
You can't directly multiply number to a time datatype.
Use function time_to_sec and sec_to_time:
update journeys, travel_type
set journeys.jo_duration = sec_to_time(
time_to_sec(journeys.jo_duration)
* travel_type.tt_duration_multiplier
mod 86400)
where journeys.jo_type = travel_type.tt_id
mod 86400 is there to remove the day part if the time becomes more than a day
I'm using spring data and am trying to write a query which returns all entries within the past week. The following is my repository code:
#Query("select l from LogEvent l where (l.entryTimestamp < CURRENT_TIMESTAMP) AND l.entryTimestamp IN l")
Page<LogEvent> findAllRecent(Pageable pageable);
I want to select all LogEvent objects which have a "entryTimestamp" variable holding the time at which they were created. I want to grab all entries created within the last 7 days. One of the issues I'm having is how to get a TIMESTAMP - 7 days that I can compare to each entity's timestamp. I've tried a number of things in looking around, like "interval '7' days" and some other examples I could find.
It's obviously lacking that week old timestamp comparison, but right now I feel like it should run and return all the LogEvent objects. As it is now, I get the following error: inconsistent datatypes: expected TIMESTAMP got NUMBER. Any pointers/help would be greatly appreciated. Thank you!
I am trying to get a total number of days hired using the DateDiff function is access.
I currently use:
=DateDiff("d",[hired_from],[hired_to])
To get the difference between two dates, however if the two dates selected are the same it will produce an output of 0, I would like it to produce an output of 1 when the two dates selected are the same, thanks.
It doesn't make much sense as the difference between two identical values always will be zero.
So you probably mean:
=DateDiff("d",DateAdd("d",-1,[hired_from]),[hired_to])
or just add one to the count:
=DateDiff("d",[hired_from],[hired_to])+1
I ended up making this work by using an if statement as shown:
==IIf(DateDiff("d",[hired_from],[hired_to])=0,1,DateDiff("d",[hired_from],[hired_to]))
to get the difference of two dates (which is only a format for an integer value), you have only to subtract the two dates and make sure that the result format is an integer.
Variable = [hired_to]-[hired_from]
T've the date column with value like 'May-10' (Say %b-%y format).While loading data to mysql, i use like
SET Period = STR_TO_DATE(#var1,'%b-%y')
Then the values are stored as '2013-05-00'. But i want to save those values in any date number
(say '2013-05-01').
I tried like doing this for May-10
DATE_ADD(DATE_SUB(DATE_FORMAT(LAST_DAY(STR_TO_DATE('May-10','%b-%y')),'%Y-%m-%d' ),INTERVAL 1 MONTH),INTERVAL 1 DAY)
I know that this is a complex way of doing things.
Anyone please suggest me simple solutions ?
Try this
SET Period = STR_TO_DATE(CONCAT('01-', #var1),'%d-%b-%y')
Okay I've tried this a few different ways and haven't been able to get it to do what I want it to. I've also visited this page: http://www.exampledepot.com/egs/javax.swing.text/formtext_FormTextDate.html
I have a spinner:
SimpleDateFormat datePattern = new SimpleDateFormat("MM/dd/yyyy");
JLabel endLabel = new JLabel("End Date: ");
JSpinner endSpinner = new JSpinner(new SpinnerDateModel());
endSpinner.setEditor(new JSpinner.DateEditor(endSpinner, datePattern.toPattern()));
This automatically loads today's date. I would prefer it to just show MM/DD/YYYY within the actual gui. This would give it the look of being date input without requiring a specific date to be entered if not required. Then as soon as you start spinning it would take a date. I can't seem to figure out how to do this. Any suggestions? I've also started looking up FormattedTextFields as well as an option. Would this be a better route to go?
If so, how can I set up the FormattedTextField to look like this: [ / / ]. Then when you put input in, keep that format, requiring only digits and 2 digits for month, 2 digits for day, and 4 digits for year. I would assume I'd have to set up some sort of pattern instead of initializing the FormattedTextField as a date? For example:
JFormattedTextField date = new JFormattedTextField(new SimpleDateFormat("MM/dd/yyyy"));
date.setValue(" / / ");
But all you would have to do is clear out the field and it would no longer look like a date. I want it to at least keep the '/' no matter what you do.
Sorry for the long drawn out question.