Thursday, September 10, 2026

Make excel file for files folder and summary list from more then 2TB Data

 For a 2 TB hard disk, I recommend making a proper Excel workbook with these sheets:

  1. Folders — every folder and its path
  2. Files — every file, path, extension, size, dates
  3. File Types.jpg, .pdf, .mp4, etc. with file count and total size
  4. Folder Usage — storage used by each top-level folder
  5. Summary — total files, folders, size, scan date

Because a 2 TB disk can contain more than 1 million files, the script below automatically creates Files_1, Files_2, Files_3, etc. when necessary because Excel has a row limit.

Before running

This version uses the Microsoft Excel installed on your PC to create the .xlsx file. You do not need to install a PowerShell Excel module.

Change this line:

$Drive = "D:\"

to your actual hard-disk drive letter, for example:

$Drive = "E:\"

Complete PowerShell script

Save this as:

Create-HardDiskInventory.ps1
# ============================================================
# HARD DISK INVENTORY TO EXCEL
# ============================================================
# Creates:
#   1. Summary
#   2. Folders
#   3. Files_1, Files_2, ...
#   4. File Types
#   5. Folder Usage
#
# Requires:
#   - Windows
#   - Microsoft Excel installed
#
# ============================================================

# -----------------------------
# CONFIGURATION
# -----------------------------

$Drive = "D:\"

$OutputFile = Join-Path `
    ([Environment]::GetFolderPath("Desktop")) `
    "HardDisk_Inventory.xlsx"

# Number of data rows per Excel Files sheet
$MaxRowsPerSheet = 1000000

# Number of records written to Excel at one time
$BatchSize = 5000


# -----------------------------
# CHECK DRIVE
# -----------------------------

if (-not (Test-Path $Drive)) {
    Write-Host "ERROR: Drive not found: $Drive" -ForegroundColor Red
    exit
}

Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " HARD DISK INVENTORY" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Drive : $Drive"
Write-Host "Output: $OutputFile"
Write-Host ""
Write-Host "Scanning... Please wait."
Write-Host ""


# -----------------------------
# DELETE OLD OUTPUT
# -----------------------------

if (Test-Path $OutputFile) {
    Remove-Item $OutputFile -Force
}


# -----------------------------
# START EXCEL
# -----------------------------

try {
    $Excel = New-Object -ComObject Excel.Application
}
catch {
    Write-Host ""
    Write-Host "Microsoft Excel is not installed or cannot be started." -ForegroundColor Red
    Write-Host ""
    exit
}

$Excel.Visible = $false
$Excel.DisplayAlerts = $false

$Workbook = $Excel.Workbooks.Add()


# -----------------------------
# REMOVE DEFAULT SHEETS
# -----------------------------

while ($Workbook.Worksheets.Count -gt 1) {
    $Workbook.Worksheets.Item($Workbook.Worksheets.Count).Delete()
}


# -----------------------------
# SUMMARY SHEET
# -----------------------------

$SummarySheet = $Workbook.Worksheets.Item(1)
$SummarySheet.Name = "Summary"


# -----------------------------
# FOLDERS SHEET
# -----------------------------

$FoldersSheet = $Workbook.Worksheets.Add()
$FoldersSheet.Name = "Folders"

$folderHeaders = @(
    "Folder Name",
    "Full Path",
    "Parent Folder",
    "Created Date",
    "Modified Date"
)

$FoldersSheet.Range("A1:E1").Value2 = ,$folderHeaders


# -----------------------------
# FILE TYPE DICTIONARY
# -----------------------------

$fileTypes = @{}

# -----------------------------
# TOP LEVEL FOLDER DICTIONARY
# -----------------------------

$folderUsage = @{}

# -----------------------------
# COUNTERS
# -----------------------------

$totalFiles = 0
$totalFolders = 0
$totalBytes = [int64]0

$scanStart = Get-Date


# ============================================================
# FUNCTION: WRITE BATCH TO EXCEL
# ============================================================

function Write-ExcelBatch {
    param (
        [Parameter(Mandatory=$true)]
        $Worksheet,

        [Parameter(Mandatory=$true)]
        [System.Collections.ArrayList]$Rows,

        [Parameter(Mandatory=$true)]
        [int]$StartRow,

        [Parameter(Mandatory=$true)]
        [int]$ColumnCount
    )

    if ($Rows.Count -eq 0) {
        return
    }

    $rowCount = $Rows.Count

    $Data = New-Object 'object[,]' $rowCount,$ColumnCount

    for ($r = 0; $r -lt $rowCount; $r++) {

        for ($c = 0; $c -lt $ColumnCount; $c++) {

            $Data[$r,$c] = $Rows[$r][$c]
        }
    }

    $EndRow = $StartRow + $rowCount - 1

    $Range = $Worksheet.Range(
        $Worksheet.Cells($StartRow,1),
        $Worksheet.Cells($EndRow,$ColumnCount)
    )

    $Range.Value2 = $Data

    [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Range) | Out-Null

    $Rows.Clear()
}


# ============================================================
# FILE SHEET CREATION
# ============================================================

$fileSheetNumber = 1
$fileSheetRow = 2

function New-FileSheet {

    param (
        [int]$Number
    )

    $sheetName = "Files_$Number"

    Write-Host "Creating sheet: $sheetName"

    $sheet = $Workbook.Worksheets.Add()

    $sheet.Name = $sheetName

    $headers = @(
        "File Name",
        "Full Path",
        "Folder",
        "Extension",
        "Size (Bytes)",
        "Size (MB)",
        "Size (GB)",
        "Created Date",
        "Modified Date",
        "Last Access Date"
    )

    $sheet.Range("A1:J1").Value2 = ,$headers

    return $sheet
}

$FileSheet = New-FileSheet -Number $fileSheetNumber


# ============================================================
# DATA ARRAYS
# ============================================================

$fileRows = New-Object System.Collections.ArrayList
$folderRows = New-Object System.Collections.ArrayList


# ============================================================
# SCAN FOLDERS AND FILES
# ============================================================

try {

    foreach ($item in [System.IO.Directory]::EnumerateFileSystemEntries(
        $Drive,
        "*",
        [System.IO.SearchOption]::AllDirectories
    )) {

        try {

            $attributes = [System.IO.File]::GetAttributes($item)

            # -----------------------------------------------
            # FILE
            # -----------------------------------------------

            if (($attributes -band [System.IO.FileAttributes]::Directory) -eq 0) {

                $fileInfo = New-Object System.IO.FileInfo($item)

                $totalFiles++
                $totalBytes += $fileInfo.Length

                # Extension
                $extension = $fileInfo.Extension.ToLower()

                if ([string]::IsNullOrWhiteSpace($extension)) {
                    $extension = "(No Extension)"
                }

                # -------------------------------------------
                # FILE TYPE STATISTICS
                # -------------------------------------------

                if (-not $fileTypes.ContainsKey($extension)) {

                    $fileTypes[$extension] = @{
                        Count = [int64]0
                        Bytes = [int64]0
                    }
                }

                $fileTypes[$extension].Count++
                $fileTypes[$extension].Bytes += $fileInfo.Length


                # -------------------------------------------
                # TOP LEVEL FOLDER
                # -------------------------------------------

                $relativePath = $item.Substring($Drive.Length)

                $parts = $relativePath.Split(
                    [char]'\',
                    [System.StringSplitOptions]::RemoveEmptyEntries
                )

                if ($parts.Count -gt 1) {
                    $topFolder = $parts[0]
                }
                else {
                    $topFolder = "(Root)"
                }

                if (-not $folderUsage.ContainsKey($topFolder)) {

                    $folderUsage[$topFolder] = @{
                        Count = [int64]0
                        Bytes = [int64]0
                    }
                }

                $folderUsage[$topFolder].Count++
                $folderUsage[$topFolder].Bytes += $fileInfo.Length


                # -------------------------------------------
                # ADD FILE TO EXCEL BATCH
                # -------------------------------------------

                $row = @(
                    $fileInfo.Name,
                    $fileInfo.FullName,
                    $fileInfo.DirectoryName,
                    $extension,
                    $fileInfo.Length,
                    [math]::Round($fileInfo.Length / 1MB, 2),
                    [math]::Round($fileInfo.Length / 1GB, 2),
                    $fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    $fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    $fileInfo.LastAccessTime.ToString("yyyy-MM-dd HH:mm:ss")
                )

                [void]$fileRows.Add($row)

                # -------------------------------------------
                # WRITE FILE BATCH
                # -------------------------------------------

                if ($fileRows.Count -ge $BatchSize) {

                    Write-ExcelBatch `
                        -Worksheet $FileSheet `
                        -Rows $fileRows `
                        -StartRow $fileSheetRow `
                        -ColumnCount 10

                    $fileSheetRow += $BatchSize

                    # ---------------------------------------
                    # EXCEL ROW LIMIT
                    # ---------------------------------------

                    if ($fileSheetRow -gt $MaxRowsPerSheet) {

                        $fileSheetNumber++

                        $FileSheet = New-FileSheet `
                            -Number $fileSheetNumber

                        $fileSheetRow = 2
                    }
                }


                # -------------------------------------------
                # PROGRESS
                # -------------------------------------------

                if (($totalFiles % 10000) -eq 0) {

                    $sizeGB = [math]::Round(
                        $totalBytes / 1GB,
                        2
                    )

                    Write-Host `
                        "Files: $totalFiles | Size: $sizeGB GB" `
                        -ForegroundColor Green
                }

            }

            # -----------------------------------------------
            # FOLDER
            # -----------------------------------------------

            else {

                $dirInfo = New-Object System.IO.DirectoryInfo($item)

                $totalFolders++

                $parent = ""

                if ($null -ne $dirInfo.Parent) {
                    $parent = $dirInfo.Parent.FullName
                }

                $row = @(
                    $dirInfo.Name,
                    $dirInfo.FullName,
                    $parent,
                    $dirInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    $dirInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
                )

                [void]$folderRows.Add($row)

                if ($folderRows.Count -ge $BatchSize) {

                    Write-ExcelBatch `
                        -Worksheet $FoldersSheet `
                        -Rows $folderRows `
                        -StartRow ($totalFolders - $BatchSize + 2) `
                        -ColumnCount 5
                }
            }

        }
        catch {
            # Ignore files/folders that Windows refuses to access
            continue
        }
    }

}
catch {

    Write-Host ""
    Write-Host "Some folders could not be scanned." -ForegroundColor Yellow
}


# ============================================================
# WRITE REMAINING FILES
# ============================================================

if ($fileRows.Count -gt 0) {

    Write-ExcelBatch `
        -Worksheet $FileSheet `
        -Rows $fileRows `
        -StartRow $fileSheetRow `
        -ColumnCount 10
}


# ============================================================
# WRITE REMAINING FOLDERS
# ============================================================

if ($folderRows.Count -gt 0) {

    $startFolderRow = $totalFolders - $folderRows.Count + 2

    Write-ExcelBatch `
        -Worksheet $FoldersSheet `
        -Rows $folderRows `
        -StartRow $startFolderRow `
        -ColumnCount 5
}


# ============================================================
# FILE TYPES SHEET
# ============================================================

$TypeSheet = $Workbook.Worksheets.Add()
$TypeSheet.Name = "File Types"

$typeHeaders = @(
    "Extension",
    "File Count",
    "Total Size (Bytes)",
    "Total Size (MB)",
    "Total Size (GB)"
)

$TypeSheet.Range("A1:E1").Value2 = ,$typeHeaders

$typeRow = 2

foreach ($ext in ($fileTypes.Keys | Sort-Object)) {

    $count = $fileTypes[$ext].Count
    $bytes = $fileTypes[$ext].Bytes

    $TypeSheet.Cells($typeRow,1).Value2 = $ext
    $TypeSheet.Cells($typeRow,2).Value2 = $count
    $TypeSheet.Cells($typeRow,3).Value2 = $bytes
    $TypeSheet.Cells($typeRow,4).Value2 = [math]::Round($bytes / 1MB, 2)
    $TypeSheet.Cells($typeRow,5).Value2 = [math]::Round($bytes / 1GB, 2)

    $typeRow++
}


# ============================================================
# FOLDER USAGE SHEET
# ============================================================

$UsageSheet = $Workbook.Worksheets.Add()
$UsageSheet.Name = "Folder Usage"

$usageHeaders = @(
    "Top Level Folder",
    "File Count",
    "Total Size (Bytes)",
    "Total Size (MB)",
    "Total Size (GB)"
)

$UsageSheet.Range("A1:E1").Value2 = ,$usageHeaders

$usageRow = 2

foreach ($folder in ($folderUsage.Keys | Sort-Object)) {

    $count = $folderUsage[$folder].Count
    $bytes = $folderUsage[$folder].Bytes

    $UsageSheet.Cells($usageRow,1).Value2 = $folder
    $UsageSheet.Cells($usageRow,2).Value2 = $count
    $UsageSheet.Cells($usageRow,3).Value2 = $bytes
    $UsageSheet.Cells($usageRow,4).Value2 = [math]::Round($bytes / 1MB, 2)
    $UsageSheet.Cells($usageRow,5).Value2 = [math]::Round($bytes / 1GB, 2)

    $usageRow++
}


# ============================================================
# SUMMARY
# ============================================================

$scanEnd = Get-Date
$duration = $scanEnd - $scanStart

$SummarySheet.Cells(1,1).Value2 = "HARD DISK INVENTORY"
$SummarySheet.Cells(3,1).Value2 = "Drive"
$SummarySheet.Cells(3,2).Value2 = $Drive

$SummarySheet.Cells(4,1).Value2 = "Scan Started"
$SummarySheet.Cells(4,2).Value2 = $scanStart.ToString("yyyy-MM-dd HH:mm:ss")

$SummarySheet.Cells(5,1).Value2 = "Scan Completed"
$SummarySheet.Cells(5,2).Value2 = $scanEnd.ToString("yyyy-MM-dd HH:mm:ss")

$SummarySheet.Cells(6,1).Value2 = "Scan Duration"
$SummarySheet.Cells(6,2).Value2 = $duration.ToString()

$SummarySheet.Cells(8,1).Value2 = "Total Folders"
$SummarySheet.Cells(8,2).Value2 = $totalFolders

$SummarySheet.Cells(9,1).Value2 = "Total Files"
$SummarySheet.Cells(9,2).Value2 = $totalFiles

$SummarySheet.Cells(10,1).Value2 = "Total Size (Bytes)"
$SummarySheet.Cells(10,2).Value2 = $totalBytes

$SummarySheet.Cells(11,1).Value2 = "Total Size (GB)"
$SummarySheet.Cells(11,2).Value2 = [math]::Round($totalBytes / 1GB, 2)

$SummarySheet.Cells(12,1).Value2 = "Total Size (TB)"
$SummarySheet.Cells(12,2).Value2 = [math]::Round($totalBytes / 1TB, 2)


# ============================================================
# FORMAT ALL WORKSHEETS
# ============================================================

Write-Host ""
Write-Host "Formatting Excel workbook..." -ForegroundColor Cyan

foreach ($sheet in $Workbook.Worksheets) {

    try {

        $usedRange = $sheet.UsedRange

        # Header row
        $headerRange = $sheet.Range(
            $sheet.Cells(1,1),
            $sheet.Cells(1,$usedRange.Columns.Count)
        )

        $headerRange.Font.Bold = $true

        # Autofilter
        if ($usedRange.Rows.Count -gt 1) {
            $usedRange.AutoFilter()
        }

        # Freeze first row
        $sheet.Activate()
        $Excel.ActiveWindow.SplitRow = 1
        $Excel.ActiveWindow.FreezePanes = $true

        # Reasonable column width
        $usedRange.Columns.AutoFit()

        # Limit extremely wide columns
        foreach ($column in $usedRange.Columns) {

            if ($column.ColumnWidth -gt 60) {
                $column.ColumnWidth = 60
            }
        }

        [System.Runtime.InteropServices.Marshal]::ReleaseComObject($usedRange) | Out-Null
        [System.Runtime.InteropServices.Marshal]::ReleaseComObject($headerRange) | Out-Null

    }
    catch {
        continue
    }
}


# ============================================================
# ACTIVATE SUMMARY
# ============================================================

$SummarySheet.Activate()


# ============================================================
# SAVE XLSX
# ============================================================

Write-Host ""
Write-Host "Saving Excel file..." -ForegroundColor Cyan

$xlOpenXMLWorkbook = 51

$Workbook.SaveAs(
    $OutputFile,
    $xlOpenXMLWorkbook
)

$Workbook.Close($true)
$Excel.Quit()


# ============================================================
# CLEANUP COM OBJECTS
# ============================================================

[System.Runtime.InteropServices.Marshal]::ReleaseComObject($SummarySheet) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($FoldersSheet) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($TypeSheet) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($UsageSheet) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($Workbook) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($Excel) | Out-Null

[GC]::Collect()
[GC]::WaitForPendingFinalizers()


# ============================================================
# FINISHED
# ============================================================

Write-Host ""
Write-Host "============================================" -ForegroundColor Green
Write-Host " SCAN COMPLETED" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Green
Write-Host ""
Write-Host "Total Folders : $totalFolders"
Write-Host "Total Files   : $totalFiles"
Write-Host "Total Size    : $([math]::Round($totalBytes / 1GB,2)) GB"
Write-Host ""
Write-Host "Excel File:"
Write-Host $OutputFile -ForegroundColor Yellow
Write-Host ""

How to run it

1. Find your hard disk drive letter

Open This PC.

For example, if your 2 TB disk is:

New Volume (D:)

then use:

$Drive = "D:\"

2. Save the script

Open Notepad, paste the complete script and save it as:

Create-HardDiskInventory.ps1

For example:

C:\Users\YourName\Desktop\Create-HardDiskInventory.ps1

3. Open PowerShell

Right-click Start → Windows PowerShell or Terminal.

Run:

Set-ExecutionPolicy -Scope Process Bypass

Then:

cd "$env:USERPROFILE\Desktop"

Then:

.\Create-HardDiskInventory.ps1

The resulting Excel file

It will be created on your Desktop:

HardDisk_Inventory.xlsx

The workbook will look approximately like:

HardDisk_Inventory.xlsx
│
├── Summary
│
├── Folders
│
├── Files_1
├── Files_2
├── Files_3
│   ...
│
├── File Types
│
└── Folder Usage

Example: File Types

ExtensionFile CountTotal Size (MB)Total Size (GB)
.jpg125,43084,52182.54
.mp412,850485,210473.84
.pdf45,21018,43017.99
.docx8,5204,2304.13

Example: Folder Usage

Top Level FolderFile CountTotal Size (GB)
Documents125,42085.42
Photos425,210620.51
Videos28,520850.32
Backup52,120310.25

One important warning

For a 2 TB disk with a very large number of files, the Excel workbook itself can become extremely large. The script handles the Excel row limit by splitting files across Files_1, Files_2, etc., but scanning can still take hours depending on the number of files and disk speed.

Also, files/folders where Windows denies access will be skipped rather than stopping the entire scan.

Create file list and path from ANY Harddidk or Drive export to excel

 If you want to make list of files from any drive or folder and make export this list to excel then windows is the best for it. Simple you have to run these commands and it will make excel file on your desktop.

If the hard disk is connected to your Windows PC, you can create an Excel list of every folder and file automatically, including:

  • Full folder/file path
  • File name
  • Extension
  • File size
  • Date modified

For 2 GB of data, this should be easy.

Easiest method — PowerShell

Suppose your hard disk is D:.

  1. Connect the hard disk.
  2. Open PowerShell.
  3. Run this command:
Get-ChildItem -Path "D:\" -Recurse -File -ErrorAction SilentlyContinue |
Select-Object FullName, Name, Extension, Length, LastWriteTime |
Export-Csv -Path "$env:USERPROFILE\Desktop\HardDisk_File_List.csv" -NoTypeInformation -Encoding UTF8

It will create:

Desktop\HardDisk_File_List.csv

Open that file with Excel.

If you also want folders

Use:

Get-ChildItem -Path "D:\" -Recurse -ErrorAction SilentlyContinue |
Select-Object FullName, Name, Extension, Length, LastWriteTime, @{Name="Type";Expression={if ($_.PSIsContainer) {"Folder"} else {"File"}}} |
Export-Csv -Path "$env:USERPROFILE\Desktop\HardDisk_Folder_File_List.csv" -NoTypeInformation -Encoding UTF8

This gives you both folders and files.

Friday, February 20, 2026

DIsplay amount in english and gujrati text

 Hello

Today I am explain how to display amount in text in both gujrati and english.


<label class="col-sm-2 control-label" title="price">Ticket Price<span class="red">*</span></label>

                                                <div class="col-sm-2" title="price">

                                                    <input type="number" class="form-control" name="ticketprice" id="ticketprice"  placeholder="Enter ticket Price" onkeypress="return onlyNumberKey(event)">

                                                    <h5 id="pricemsg" style="color: red;">Please fill Ticket Price</h5>

                                                </div>

                                                <span class="col-sm-4 green" title="price">

                                                    <strong>

                                                        <span id="amountWords"></span><br>

                                                        <span id="amountWordsG"></span>

                                                    </strong>

                                                </span>

                                            </div>


JS code:

<script>

        //gujrati

        const gujaratiNumbers = [

                                    "", "એક", "બે", "ત્રણ", "ચાર", "પાંચ", "છ", "સાત", "આઠ", "નવ",

                                    "દસ", "અગિયાર", "બાર", "તેર", "ચૌદ", "પંદર", "સોળ", "સત્તર", "અઢાર", "ઓગણીસ",

                                    "વીસ", "એકવીસ", "બાવીસ", "ત્રેવીસ", "ચોવીસ", "પચ્ચીસ", "છવીસ", "સત્તાવીસ", "અઠ્ઠાવીસ", "ઓગણત્રીસ", "ત્રીસ", "એકત્રીસ", "બત્રીસ", "તેત્રીસ", "ચોત્રીસ", "પાંત્રીસ", "છત્રીસ", "સાડત્રીસ", "આડત્રીસ", "ઓગણચાલીસ",

                                    "ચાલીસ", "એકતાલીસ", "બેતાલીસ", "તેતાલીસ", "ચુંમાલીસ", "પિસ્તાલીસ", "છેતાલીસ", "સુડતાલીસ", "અડતાલીસ", "ઓગણપચાસ",

                                    "પચાસ", "એકાવન", "બાવન", "તેપન", "ચોપન", "પંચાવન", "છપ્પન", "સત્તાવન", "અઠ્ઠાવન", "ઓગણસાઠ",

                                    "સાઠ", "એકસઠ", "બાસઠ", "તેંસઠ", "ચોસઠ", "પાંસઠ", "છાંસઠ", "સડસઠ", "અડસઠ", "ઓગણસિત્તેર",

                                    "સિત્તેર", "એકોતેર", "બોતેર", "તોતેર", "ચુમોતેર", "પંચોતેર", "છોતેર", "સિત્યોતેર", "ઇઠ્યોતેર", "ઓગણએંસી",

                                    "એંસી", "એક્યાસી", "બ્યાસી", "ત્ર્યાસી", "ચોર્યાસી", "પંચ્યાસી", "છ્યાસી", "સિત્યાસી", "ઈઠ્યાસી", "નેવ્યાસી",

                                    "નેવું", "એકાણું", "બાણું", "ત્રાણું", "ચોરાણું", "પંચાણું", "છન્નું", "સત્તાણું", "અઠાણું", "નવ્વાણું"

                                ];

        const gujaratiHundreds = {

                                    1: "એકસો",

                                    2: "બસો",

                                    3: "ત્રણસો",

                                    4: "ચારસો",

                                    5: "પાંચસો",

                                    6: "છસો",

                                    7: "સાતસો",

                                    8: "આઠસો",

                                    9: "નવસો"

                                };



        function numberToGujaratiWords(num) {

            if (!num || num === 0) return "";


            function convertBelow1000(n) {

                let str = "";


                if (n >= 100) {

                    const h = Math.floor(n / 100);

                    str += gujaratiHundreds[h] + " ";

                    n = n % 100;

                }


                if (n > 0) {

                    str += gujaratiNumbers[n];

                }


                return str.trim();

            }


            let result = "";


            const crore = Math.floor(num / 10000000);

            const lakh = Math.floor((num % 10000000) / 100000);

            const thousand = Math.floor((num % 100000) / 1000);

            const rest = num % 1000;


            if (crore) result += convertBelow1000(crore) + " કરોડ ";

            if (lakh) result += convertBelow1000(lakh) + " લાખ ";

            if (thousand) result += convertBelow1000(thousand) + " હજાર ";

            if (rest) result += convertBelow1000(rest);


            return result.trim() + " રૂપિયા પુરા.";

        }


        //english

        function numberToWords(num) {

            num = parseInt(num);

            if (isNaN(num)) return '';


            const belowTwenty = ['', 'One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten',

                'Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'];


            const tens = ['', '', 'Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'];


            function convertHundreds(n) {

                let str = '';


                if (n > 99) {

                    str += belowTwenty[Math.floor(n / 100)] + ' Hundred ';

                    n = n % 100;

                }


                if (n > 19) {

                    str += tens[Math.floor(n / 10)] + ' ';

                    n = n % 10;

                }


                if (n > 0) {

                    str += belowTwenty[n] + ' ';

                }


                return str;

            }


            let result = '';


            if (num >= 10000000) {

                result += convertHundreds(Math.floor(num / 10000000)) + 'Crore ';

                num = num % 10000000;

            }


            if (num >= 100000) {

                result += convertHundreds(Math.floor(num / 100000)) + 'Lakh ';

                num = num % 100000;

            }


            if (num >= 1000) {

                result += convertHundreds(Math.floor(num / 1000)) + 'Thousand ';

                num = num % 1000;

            }


            if (num > 0) {

                result += convertHundreds(num);

            }


            return result.trim();

        }


        document.getElementById("ticketprice").addEventListener("input", function () {


            let value = this.value;


            if (value == "" || value == 0) {

                document.getElementById("amountWords").innerText = "";

                return;

            }


            document.getElementById("amountWords").innerText =

                numberToWords(value) + " Rupees Only";


            //gujrati

            const output = $('#amountWordsG');

            if (!isNaN(value) && value > 0) {

                output.text(numberToGujaratiWords(value));

            } else {

                output.text('');

            }


        });

    </script>

Friday, June 27, 2025

Count days between two dates

 Here I am explaining code for count days between two dates.





<!DOCTYPE html>


<html lang="en">

<head>

<meta charset="UTF-8">

<title>Date Difference - Years, Months, Days</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

</head>

<body class="p-4">




<div class="container">

<h3 class="mb-4">વાદગ્રસ્ત હુકમ તારીખ અને દાખલ તારીખ : વર્ષો, મહિનાઓ અને દિવસોની ગણતરી કરો</h3>

<div class="row mb-3">

<div class="col-md-6">

<label for="date1" class="form-label">વાદગ્રસ્ત હુકમ તારીખ (dd/mm/yyyy)</label>

<input type="text" id="date1" class="form-control" placeholder="dd/mm/yyyy">

</div>




<div class="col-md-6">

<label for="date2" class="form-label">દાખલ તારીખ (default: today)</label>

<input type="date" id="date2" class="form-control">

</div>

</div>




<div id="reultdiv"></div>

</div>




<script>

document.getElementById('date2').valueAsDate = new Date();




document.getElementById('date1').addEventListener('change', calculate);

document.getElementById('date2').addEventListener('change', calculate);




function calculate() {

document.getElementById("reultdiv").innerHTML = '';




const date1Str = document.getElementById('date1').value;

const date2Str = document.getElementById('date2').value;




const parts = date1Str.split('/');

if (parts.length !== 3) return;




const d1 = new Date(`${parts[2]}-${parts[1]}-${parts[0]}`);

const d2 = new Date(date2Str);

if (isNaN(d1.getTime()) || isNaN(d2.getTime())) return;




let output = '';




// Helper function to calculate and return HTML

function getAlertHTML(label, className, from, to) {

let totalDays = Math.floor((to - from) / (1000 * 60 * 60 * 24));

if (totalDays < 0) return ''; // skip if invalid range




let years = to.getFullYear() - from.getFullYear();

let months = to.getMonth() - from.getMonth();

let days = to.getDate() - from.getDate();




if (days < 0) {

months--;

let temp = new Date(to.getFullYear(), to.getMonth(), 0);

days += temp.getDate();

}




if (months < 0) {

years--;

months += 12;

}




return `

<div class="alert ${className}" role="alert">

<strong>${label}</strong><br>

🗓 <strong>કુલ દિવસો:</strong> ${totalDays} દિવસ<br>

📅 <strong>અવધિ:</strong> ${years} વર્ષ, ${months} મહિના, ${days} દિવસ

</div>

`;

}




// 🔹 Primary calculation

if (d1 <= d2) {

output += getAlertHTML("પ્રાથમિક ગણતરી", "alert-primary", d1, d2);

}




// 🔹 30 days check

let d30 = new Date(d2);

d30.setDate(d30.getDate() - 30);

if (d1 <= d30) {

output += getAlertHTML("30 દિવસ પહેલાની ગણતરી", "alert-info", d1, d30);

}




// 🔹 60 days check

let d60 = new Date(d2);

d60.setDate(d60.getDate() - 60);

if (d1 <= d60) {

output += getAlertHTML("60 દિવસ પહેલાની ગણતરી", "alert-warning", d1, d60);

}




// 🔹 90 days check

let d90 = new Date(d2);

d90.setDate(d90.getDate() - 90);

if (d1 <= d90) {

output += getAlertHTML("90 દિવસ પહેલાની ગણતરી", "alert-danger", d1, d90);

}




document.getElementById("reultdiv").innerHTML = output;

}

</script>




</body>

</html>