wrong date when i change int time with FROM_UNIXTIME - date

I have a old database that i want to transfer, but i have some trouble with my column dateP(int). I got a wrong datetime.
In my old script, I enter the date-time like this:
$date_created = time();
$data_insert = "INSERT TO table $date_created, $title";
Now I have the column datePub (int) that I convert to time stamp format,
For resolve this problem i make this.
UPDATE `table ` SET `date_created` = FROM_UNIXTIME(`datePub `)
But I got a wrong date when I make this date('M d, Y', $PuDate);

I put the right specifier in date_format and its good now.

Related

Google Sheets - DATE format not working on imported Date in TEXT format

I text based .csv file with a semicolon separated data set which contains date values that look like this
22.07.2020
22.07.2020
17.07.2020
09.07.2020
30.06.2020
When I go to Format>number> I see the Google sheets has automatic set.
In this state I cannot use and formulas with this data.
I go to Format>number> and set this to date but formulas still do not see the actual date value and continue to display an error
Can someone share how I can quickly activate the values of this array so formulas will work against them?
I would be super thankful
Where the date are in column A, starting in cell A1, this formula will convert to DATE as a number, after which you apply formatting to Short Date style.
=ARRAYFORMULA(IF(A1:A="",,DATE(RIGHT(A1:A,4),MID(A1:A,4,2),LEFT(A1:A,2))))
Hopefully(!) the dates stay as text, otherwise Google Sheets would sometimes detect MM/dd/yyyy instead of dd/MM/yyyy, and you won't be able to distinguish between July 9th and September 7th in your example.
Solution #1
If your locale is for instance FR, you can then apply
=arrayformula(if(A1:A="";;value(A1:A)))
solution#2
you can try/adapt
function importCsvFromIdv1() {
var id = 'the id of the csv file';
var csv = DriveApp.getFileById(id).getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
csvData.forEach(function(row){
date = row[0]
row[0] = date.substring(6,10)+'-'+date.substring(3,5)+'-'+date.substring(0,2)
})
var f = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
f.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First thanks to those that suggested a fix. I am not really a programmer and get cold sweats when I see suggesting of running scripts to solve simple problems. Sorry guys.
So the (non programmer) solution with the dates was to do a find/replace (CTRL + H) and replace all the (.)dots with (/)slashes, then to make sure the column is formatted as a date, then Google finally understands it as a date.
With the accounting values as well, I had to do the same find/replace to remove all the ' between thousands, then google woke up and understood them as numbers.
I am significantly underwhelmed by this from Google. They are getting too fat and lazy. They need some competition.

Teradata Date calculation format issue

I have this date set uploaded from SAS to TD and the date format is like MEDI_START_DT format,'MM/DD/YYYY'
And now I want to make a calculation baesed on this column
MEDI_START_DT + PDAYSSUP -1 = MEDI_END_DT_PRE
but MEDI_END_DT_PRE's format is not a date and I tried cast(MEDI_END_DT_PRE's as date) and it says invalid date.
Do you guys have any idea on how to get a date format result after the calculation? Thanks!
enter image description here
If you loaded the data from SAS and it was formatted as a DATE in SAS then it should work. You should check if your PDAYSSUP variable got defined as FLOAT in Teradata. Try casting that variable:
select MEDI_START_DT + cast(PDAYSSUP as integer) -1 as MEDI_END_DT_PRE
from ...

Format date and add month to it

I'm currently working with embarcadero c++, this is the first time I'm working with it so it's completely new to me.
What I'm trying to achieve is to get the current date, make sure the date has the "dd/MM/yyyy" format. When I'm sure this is the case I want to add a month to the current date.
So let's say the current date is 08/18/2016 this has to be changed to 18/08/2016 and then the end result should be 18/09/2016.
I've found that there is a method for this in embarcardero however I'm not sure how to use this.
currently I've only been able to get the current date like this.
TDateTime currentDate = Date();
I hope someone will be able to help me out here.
I figured it out.
After I've searched some more I found the way to use the IncMonth method on this page.
The example given my problem is as follows:
void __fastcall TForm1::edtMonthsExit(TObject *Sender)
{
TDateTime StartDate = edtStartDate->Text;
int Months = edtMonths->Text.ToInt();
TDateTime NextPeriod = IncMonth(StartDate, Months);
edtNextPeriod->Text = NextPeriod;
}
After looking at I changed my code accordingly to this
TDateTime CurrentDate = Date();
TDateTime EndDate = IncMonth(CurrentDate, 1);
A date object doesn't have a format like "dd/MM/yyyy". A date object is internally simply represented as a number (or possibly some other form of representation that really isn't your problem or responsibility).
So you don't have to check if it's in this format because no date objects will ever be in this format, they simply don't have a format.
You will have to do additions/subtractions on the Date object that the language or library gives you, THEN (optionally) you can format it to a human-readable string so it looks like 18/08/2016 or 18th of August 2016 or whatever other readable format that you choose.
It might be that the TRANSFER of a date between 2 systems is in a similar format, but then formatting the date like that is entirely up to you.
As for how to do that, the link you posted seems like a possible way (or alternatively http://docwiki.embarcadero.com/Libraries/Berlin/en/System.SysUtils.IncMonth), I'm afraid I can't give you an example as I'm not familiar with the tool/language involved, I'm just speaking generically about Date manipulations and they should ALWAYS be on the raw object.

Converting string with format "2014-08-12-12:42:38:133936" to datetime

I have an issue converting this string coming from a web service into a datetime for our database.
I know I could take a substring of each side date / time and format the hell out of it so that i would essentially break it apart and add the time back to the date, but there has to be a more simple way. I am terrified if I do it the "hack" way then somewhere down the line there will be a date that will break the logic.
So does anyone have a tip in converting a string with the format "2014-08-12-12:42:38:133936" into a Datetime datatype?
If you don't need to need to keep the accuracy to yyyy-mm-dd hh:mm:ss.mmmmmm or you are happy with yyyy-mm-dd hh:mm:ss.mmm
This should do it:
DECLARE #value VARCHAR(MAX) = '2014-08-12-12:42:38:133936'
SELECT convert(datetime, STUFF(SUBSTRING(#value,1,LEN(#value)-3),11,1,' '), 21)
or
SELECT CAST(STUFF(SUBSTRING(#value,1,LEN(#value)-3),11,1,' ')AS DATETIME )

Date display Appery.io

I use a date picker that saves the date in a yyyy-mm-dd format in a database. It then automatically adds time that always appears as 00:00:00. So for example it displays the date like this : 2014-12-14 00:00:00. I want it to display just the date in a mm-dd-yyyy format.
I use the code below but something seems to be wrong with it because it simply doesn't change the way it is displayed. I want to split up each of the values, then display only the date in a different format.
var parts = value.split("/");
return parts[1] + "-" +parts[2] + "-" +parts[0];
What can I do to make it work? Javascript please.
Thanks in advance.
It's a wide variety of solutions. Depends on you server-side settings too, but I will assume, that you use common for most websites MySQL DB and PHP.
You can change you column type to DATE. As said in docs:
The DATE type is used for values with a date part but no time part.
MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The
supported range is '1000-01-01' to '9999-12-31'.
You can change your column type to VARCHAR and store a date in any format you like when INSERT it
You can convert it to proper format using MySQL built-in DATE_FORMAT()
SELECT DATE_FORMAT('2014-12-14 00:00:00', '%c-%e-%Y');
will give you 12-14-2014. Here is sqlfiddle,
just change first param to your column name in query
On server you can use PHP's date() function like this
$yourdate = '2014-12-14 00:00:00';
echo date("m-d-Y", strtotime($yourdate));
Closer to your question, how to do it in JS? It also has special object for this: Date(). Put your date in constructor, then use methods:
var yourdate = new Date('2014-12-14 00:00:00');
alert(yourdate.getMonth() + "-" + yourdate.getDate() + "-" + yourdate.getFullYear());
JSFiddle < - here
So, as far as almost every platform understands this datetime format - you can use any tool for converting it