Sign in to follow this  
Followers 0
Athos

Time and Date Hashed in excel

6 posts in this topic

#1 ·  Posted (edited)

Hi guys, I have a question about getting rid of the hashes associated with time and date in excel.

Ok, so I have a program that generates a lot of data for an excel spreadsheet.

And when it writes the data to excel, it includes the time and date.

keep in mind this is just the start of the array

Local $aArray[60] = [ _NowDate(), _NowTime()]

The important thing Is I'm using the time and date from date.au3

However, when, it spits out this data in excel I get something like

#### <-Should be date

#### <-Should be time

The reason for this is that the A column in excel apparenlty doesn't have enough space for the time and date, and will turn them into hashes if its not enough space.

So for a while I just accepted that and didn't worry about it(i could just increase the size of the column if I needed to see that info)......

....that is of course, until I started aggregating my data from multiple excel sheets into 1 excel sheet.

I made a script that takes the data from each book, and puts it into 1 big array, and then shoots that out into an excel sheet.

So while that works all and good, the result is that it gives weird numbers where the time and the date are.

20120716000000 <-should be the time

0.733391203703704 <-should be the data

So the first one I can sort of see where the date is in that number. However the 2nd one is all weird (maybe it's 7:33)

Regardless, I just want to get my dates looking like this in the aggregated excel:

7/16/2012

5:12:53 PM

Edited by Athos

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Excel stores time as a fractional portion of a 24-hour day.

So 73.339 percent of 24 hours puts you right at 17.6 hours which is 5:36pm

$excel_time = .73339 * 24
$hours = Int($excel_time)
$minutes = Int(($excel_time - $hours) * 60)
MsgBox(0,"", $hours & ":" & StringRight("0" & $minutes, 2))
Edited by Spiff59

Share this post


Link to post
Share on other sites

Ah, that's great to hear thanks :)

Regardless, I would still like to get the time and date back in a more legible format.

Share this post


Link to post
Share on other sites

Expand the size of the column to fit the text in it, the information is there correctly, it's just that the size of the column is wrong.

Here's a modified script from the examples in the help file, it will create a new workbook, and then resize columns 1 and 2 to the width of the contents in the 2 columns.

#include <Excel.au3>
$oExcel = _ExcelBookNew() ;Create new book, make it visible
For $i = 1 To 5 ;Loop
     _ExcelWriteCell($oExcel, $i, 1, $i) ;Write to the Cell Horizontally using values 1 to 5
Next
ToolTip("AutoSize Columns Soon...")
Sleep(3500)
For $x = 1 To 2
     $oExcel.ActiveSheet.Columns($x).Autofit() ; resize columns 1 and 2 to autofit the width of the contents
Next
MsgBox(0, "Exiting", "Press OK to Save File and Exit")
_ExcelBookSaveAs($oExcel, @TempDir & "Temp.xls", "xls", 0, 1) ; Now we save it into the temp directory; overwrite existing file if necessary
_ExcelBookClose($oExcel) ; And finally we close out

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewMan: While I was indeed able to increase the size of the column, making both the time and date visible, copying them to the aggregated excel sheet still formated the time and date as decimals :(

I think it's worth noting that I'm getting my data to the array using _ExcelReadSheetToArray().

Share this post


Link to post
Share on other sites

Please post your code so that I can see what's happening and try to trouble shoot it. I really don't want to have to go through a process and then find out you're doing it another way and have to start all over again. A short reproducer would be best if your script is very long.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • LoneWolf_2106
      By LoneWolf_2106
      Hi all,
      i have an empty csv file, i have a non formatted text file.
      What do i want to do?
      I want to automate the process "get external data" in Excel, i want to import the data from the text file and basically create a csv file with a specific character encoding.
      Is it possible with AutoIT?
       
    • breakbadsp
      By breakbadsp
      I  want to create a excel file from my script if it does not exist.
      _ExcelBookOpen throws error=2 if file does not exist, after this error i want to create new file at this point.
      can i use _FileCreate()?
      _Logger($sLogPath, "{INFO}------: Opening Excel File: " & $sExcelPath& "") While 1 Local $oExcelTestResult = _ExcelBookOpen($sExcelPath) If @error = 2 Then If not _FileCreate($sResExcelPath) Then MsgBox(0, "Error", "Error In Opening REsult Excel File: Error: " & String(@error)) _Logger($sLogPath, "{ERROR}------: Result Excel File does not exist.. tried to create new but :ERROR : " & String(@error) & "") ExitLoop Else _Logger($sLogPath, "{INFO}------: Result Excel File does not exist.. **Created New**: ") EndIf Else ExitLoop EndIf WEnd  
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to store an entire row of a Excel workbook into an array.  The row index is stored in a variable.
      How can i do it?
      Thanks in advance for your support.
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to write a value into an excel column.
      I know where it starts from, but i don't know what the end is, last non-empty cell.
      How can i get the number of last non-empty cell?
      Thanks in advance.
      Regards 
    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?