How do I make a date representation ('1/1/2014') from = 3-1-2014 5:50:46, Function loadDatabaseFromSheet() - date

I am new to Appsript Script.Db
We have a spreadsheet whit about 300 row's of date in the first column date : 3-1-2014 5:50:46.
When we do a function loadDatabaseFromSheet() we get the error date Timestamp is not a number.
ScriptDB cannot store Date objects directly; instead, you must store a representation of the >date and reconstruct it later. If you don't intend to search based on dates, then you can >store the numeric timestamp from the Date object like this:
var date = new Date('1/1/2014');
var item = {
timestamp: date.getTime();
}
var record = db.save(item);
Do we have change all the date by hand in a proper way from 3-1-2014 5:50:46 to '3/1/2014'?
Hope that there is a better way to get this done?
// How and where can i make a representation: ('1/1/2014'); I hope i don't have to change
// all the date's in the spreadsheet by hand ?My spreadsheet has 300 Row's, first collumn =

The script DB cannot save Date datatype by default, so what you need to do is covert it to its time representation and save it to DB as the above info suggests.
As for your question regarding the need to change date format, it will not be necessary just do a (new Date(value)).getTime() at the time of saving to the DB. Where value represents the datetime in the first column.

Related

Converting timestamp object to date with difference in flutter

Let’s say I have an object of type Timestamp set to 2 days from now.
How to get the difference in time and then format it in DateFormat('hh : mm : ss') in dart ?
Construct a DateTime from the Timestamp.
Subtract from that DateTime the initial time (which I presume should be DateTime.now()) to get a Duration.
Format the Duration. Its default .toString() implementation uses hh:mm:ss.microseconds, which is close to what you want. If you want more control, you can easily format it yourself.
var dateTime = DateTime.fromMicrosecondsSinceEpoch(timestamp.timestamp!);
var duration = dateTime.difference(DateTime.now());
print(duration);

MomentJS date string adds one day

I don't understand why this date is saved as +1 day:
startdate = "2017-11-29T23:59:59.999Z";
var new_date = moment(startdate).format('DD/MM/YYYY'); // --> gives 30/11/2017
But if I do:
startdate = "2017-11-29";
var new_date = moment(startdate).format('DD/MM/YYYY'); // --> gives the correct date 29/11/2017
Any ideas?
Here is a jsfiddle showing this: http://jsfiddle.net/jbgUt/416/
Thanks!
If a time part is included, an offset from UTC can also be included as +-HH:mm, +-HHmm, +-HH or Z.
Add utc() to avoid it.
moment(startdate).utc().format('DD-MM-YYYY')
or
moment.utc(startdate).format('DD-MM-YYYY')
If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment()
Late to the party on this one, but I did just convert a few of our product's date-time objects to https://moment.github.io/luxon/
Takes out the need for the .utc() method above.

How to simulate user input in a LibreOffice Base Form via an event driven macro

I have a LibreOffice Base form that allows me to manually add rows to a table. However, the first field of every row is almost always a duplicate of the previous rows first field - Date. Via a macro, I want to automatically fill in the date field so I don't have to manually repeat the information.
Using the PriorToReset event handler, I tried the following:
Sub Main
Dim defaultDate as string
End Sub
Sub PriorToReset(event)
dim Form
dim DateField
Form=event.source
DateField = Form.getByName("Date")
if DateField.Text = "" then
defaultDate = Date
DateField.Text = defaultDate
else
defaultDate = DateField.Text
end if
End Sub
This does put the current date into an empty row, but when I fill out the remaining fields and attempt to save the row, it objects by saying that the Date field is empty. I'm looking at todays date in that field, but the system acts like its empty. If I backspace over just the last digit, replace it and hit enter it accepts it.
Obviously just dumping the date into the "Text" property does not set the indicator that data has been entered. I also experimented with:
DateField.setPropertyValue("Text", defaultDate)
But that errors out completely.
How do I simulate data entry via a macro?
Set the date property of DateField using a variable declared as an UNO Date Struct.
First, declare the struct. Then set the values of the individual members of the struct (year, month, day). Then set the date property to equal the struct and commit.
Adapt this code example to suit:
Sub change_a_date
Dim adate As New com.sun.star.util.Date
root_form = ThisComponent.Drawpage.Forms
main_frm = root_form.getByName("MainForm")
adate.year = 1990
adate.month = 7
adate.day = 4
main_frm.getByName("date_bx").date = adate
main_frm.getByName("date_bx").commit
End Sub
Declaration based on example for IsStruct function. See also API reference for UNO Date Struct.

PHPExcel How to set a date in cell

I need to put a date in a cell, when I take a look to its format it looks like *14/03/01.
The value I put is a simple string and for that reason when I get the calculated values ignores the date I entered because it compares in a calendar (well, a column with all the dates of the actual year) the date that I entered with the dates to set a proper value corresponding the date entered.
Is there a way to put the format that Excel expects?
MS Excel uses a timestamp value for dates, and then masks it for display purposes; not a formatted string.
From 02types.php in the /Examples folder:
$dateTimeNow = time(); // Get a Unix/PHP timestamp value for the date/time
$objPHPExcel->getActiveSheet() // Convert Unix timestamp to a MS Excel
->setCellValue('A9', 'Date/Time') // serialized timestamp, and set that as
->setCellValue('B9', 'Date') // the cell value
->setCellValue(
'C9',
PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )
);
$objPHPExcel->getActiveSheet() // Format as date and time
->getStyle('C9')
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
The PHPExcel_Shared_Date::PHPToExcel() method will take a Unix timestamp or a string (formatted like those you might pass to strtotime()) and convert it to a MS Excel timestamp value; while the setFormatCode() calls are setting that cell to a format mask to indicate to MS Excel that the cell contains a value that should be displayed as a date and/or time
$duree = '08:00:00';
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
$sheet->setCellValueByColumnAndRow($row, $num, $duree);
$sheet->getStyleByColumnAndRow($row, $num)
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3);
And in my cell i can see 08:00

What type should you store the date in a database?

Currently I'm storing it as a String, but got problems using it when it comes to querying by date with GQL.
Date date = Calendar.getInstance().getTime();
DateFormat formatter = new SimpleDateFormat("hh:mm:ss, z");
String todayDate = formatter.format(date);
The query:
"SELECT FROM SomeTable p WHERE date = 01/01/2011"
Error:
Exception:
org.datanucleus.store.appengine.query.DatastoreQuery$UnsupportedDatastoreFeatureException:
Problem with query : Right side of expression is
composed of unsupported components.
Left:
org.datanucleus.query.expression.Literal,
Op: / , Right:
DyadicExpression{Literal{5} /
Literal{11}}
How can I search by date?
Always as a date - the database should check on the types of data that it stores thus making sure the data is what it says. the information about what type is known on the insert so check it then rather than later when none has any idea of what the correct value should have been.
the error you are getting is probably not due to this but because the date in the query needs to be made a date if types are correct or if a string needs to be as a single-quoted string see GQL Reference
e.g.
"SELECT FROM SomeTable p WHERE date = '01/01/2011'"
but what date is 06/07/2011 ? I think it is today 6th July, others 7th June. So even if you use strings use the ISO format 2011-07-06 A date type will hide this detail making it easier. Note that GQL only uses the ISO form so even if you got the command to have the date in a string it would fail.
but better as
SELECT FROM SomeTable p WHERE date = DATE( 2011, 1, 1)