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,
      i have an error:
      ==> The requested action with this object has failed.: $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count $iRowCount = .Range(^ ERROR  
      My code is:
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) Sleep(1000) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count Sleep(1000) _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount) I have added some sleep because the application was crashing more often before, so i thought to slow down the code execution.
      But i didn't solve the issue.
      Has anyone an idea of what the problem might be?
      Thanks in advance.
    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Written by GreenCan and water.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have a problem with the deletion of an empty row in Excel.
      My code:
       
      If $vRow_2 = "" Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf I want to delete the second row. $vRow_2 is an empty cell, "A2".
      After running the code, the second row is not deleted.
      I have tried also:
       
      If $vRow_2 = Null Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf But it doesn't work.
      Any suggestion?
      Thanks in advance.
    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question about Excel, i have to create several charts one below the other dynamically.
      I have thought to use:
       
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count  
      And then to use it in this way:
      $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts.
      Does anyone have a suggestion?