Jump to content

Time and Date Hashed in excel


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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().

Link to comment
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

Link to comment
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
 Share

×
×
  • Create New...