Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: Geburtsdatum von Jahr, Monat, Tag nach Tag, Monat, Jahr ändern?

    Scubi

    • Mitglied
    • Beiträge: 220
    Moin,

    das Datum für den Geburtstag wird in der Datenbank so gespeichert:  1970-08-17 Sprich Jahr, Monat Tag.
    Für einen Import in ein anderes Programm benötige ich das Datum in folgendem Format:  17.08.1970 also Tag, Monat, Jahr.

    Wie kann man das umrechnen oder beim Export in die CSV Datei gleich richtig machen?

    Gruß Scubi

    Linkback: https://www.modified-shop.org/forum/index.php?topic=40983.0

    noRiddle (revilonetz)

    • Experte
    • Beiträge: 13.724
    • Geschlecht:
    Wie holst du denn das Datum aus der DB und wie schreibst du's in die CSV ?
    Gib' mal Code.
    Mich stört, mit Verlaub, an solchen Fragen, daß es wirkt als wolle man Fertig-Lösungen haben, wenn man nicht einmal dazuschreibt was man bislang hat.
    Da hält sich der Wille meiner Wenigkeit zu helfen in gewissen Grenzen.

    Suche mal nach PHP strtotime und date und/oder nach mySQL UNIX_TIMESTAMP und PHP date oder auch mySQL DATE_FORMAT.

    Gruß,
    noRiddle

    Scubi

    • Mitglied
    • Beiträge: 220
    Ich habe zwei Möglichkeiten. Ich habe ein Script das ich aufrufen kann. Daraus wird dann eine csv Datei generiert. Die andere Möglichkeit ist der Export über phpmyadmin.

    Code: PHP  [Auswählen]
    <?php
    define('NEWSLETTER_PATH', 'meine-domain.com/import/');
    $fileName = NEWSLETTER_PATH.date("dmy");

    for ($i=1; $i<100; $i++)
    {
            $tFileName = $fileName.'-'.$i.'.csv';
            if (!file_exists($tFileName))
            {
                    $currentFileName = $tFileName;
                    break;
            }
    }

    function ReplaceTiltChars($data)
    {
            return str_replace(';', ' ', $data);
    }

    function FormatBirthday($birtdayFromDatabase)
    {
            return str_replace(' 00:00:00', '', $birtdayFromDatabase);     
    }

    function TranslateGender($genderType)
    {
            if ($genderType == 'm')
            {
                    return 'Herr';
            }
            else if ($genderType == 'f')
            {
                    return 'Frau';
            }
            else
            {
                    return '';
            }
    }

    function TranslateSex($genderType)
    {
            if ($genderType == 'm')
            {
                    return 'm';
            }
            else if ($genderType == 'f')
            {
                    return 'w';
            }
            else
            {
                    return 'undefined';
            }
    }

    require ('includes/application_top.php');
           
            $orders_query = xtc_db_query("SELECT    o.orders_id,
                                                                                            o.customers_id,
                                                                                            c.customers_id,
                                                                                            c.customers_firstname,
                                                                                            c.customers_lastname,
                                                                                            c.customers_email_address,
                                                                                            c.customers_gender,
                                                                                            c.customers_dob,
                                                                                            c.customers_telephone,
                                                                                            o.customers_postcode,
                                                                                            o.customers_city,
                                                                                            o.customers_street_address
                                                                            FROM    orders o
                                                                            LEFT JOIN customers c
                                                                            ON              c.customers_id = o.customers_id
                                                                            WHERE   ( o.orders_status=3 OR o.orders_status=7 )
                                                                            AND     c.IsInNewsletter=0"
    );
           
            $loopInt = 1;
            //$output = 'geschlecht;anrede;vorname;nachname;email;birthday;telefon;plz;ort;street'. PHP_EOL;
            $output = 'geschlecht;anrede;vorname;nachname;email'. PHP_EOL;
           
            if ( xtc_db_num_rows($orders_query) > 0 )
            {
                    while($orders = xtc_db_fetch_array($orders_query))
                    {
                            // Anrede muss mit Join noch ausgelesen werden.
                            $output .= TranslateSex($orders['customers_gender']); // Anrede
                            $output .= ';';
                            $output .= TranslateGender($orders['customers_gender']); // Anrede
                            $output .= ';';
                            $output .= ReplaceTiltChars($orders['customers_firstname']); // Vorname
                            $output .= ';';
                            $output .= ReplaceTiltChars($orders['customers_lastname']); // Nachname
                            $output .= ';';
                            $output .= ReplaceTiltChars($orders['customers_email_address']); // Email Adresse
                            //$output .= ';';
                            //$output .= FormatBirthday($orders['customers_dob']); // Geburtsdatum
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_telephone']); // Telefon
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_postcode']); // PLZ
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_city']); // Ort
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_street_address']); // Ort
                            $output .= PHP_EOL;
                           
                            $update = "UPDATE customers SET IsInNewsletter='' WHERE customers_id='".$orders['customers_id']."';";
                            xtc_db_query($update);
                            // Wenn Datensatz erfasst wurde, dann muss die Order auf Status IsInNewsletter=1 gesetzt werden.
                            $loopInt++;
                    }
                   
                    if ($loopInt > 1)
                    {
                            $handle = fopen($currentFileName, 'w');
                            fputs($handle, $output);
                            fclose($handle);
                    }
                   
            }
            //echo $loopInt;
            header('Location: orders.php');


    ?>

    hpzeller

    • Experte
    • Beiträge: 4.130
    • Geschlecht:
    Hallo Scubi,

    so sollte dein Skript das Geburtsdatum so ausgeben wie du es haben willst. Nicht getestet!

    Code: PHP  [Auswählen]
    <?php
    define('NEWSLETTER_PATH', 'meine-domain.com/import/');
    $fileName = NEWSLETTER_PATH.date("dmy");

    for ($i=1; $i<100; $i++)
    {
            $tFileName = $fileName.'-'.$i.'.csv';
            if (!file_exists($tFileName))
            {
                    $currentFileName = $tFileName;
                    break;
            }
    }

    function ReplaceTiltChars($data)
    {
            return str_replace(';', ' ', $data);
    }

    function FormatBirthday($birtdayFromDatabase)
    {
            $d = explode("-", str_replace(' 00:00:00', '', $birtdayFromDatabase));
            return sprintf("%02d.%02d.%04d", $d[2], $d[1], $d[0]);      
    }

    function TranslateGender($genderType)
    {
            if ($genderType == 'm')
            {
                    return 'Herr';
            }
            else if ($genderType == 'f')
            {
                    return 'Frau';
            }
            else
            {
                    return '';
            }
    }

    function TranslateSex($genderType)
    {
            if ($genderType == 'm')
            {
                    return 'm';
            }
            else if ($genderType == 'f')
            {
                    return 'w';
            }
            else
            {
                    return 'undefined';
            }
    }

    require ('includes/application_top.php');
           
            $orders_query = xtc_db_query("SELECT    o.orders_id,
                                                                                            o.customers_id,
                                                                                            c.customers_id,
                                                                                            c.customers_firstname,
                                                                                            c.customers_lastname,
                                                                                            c.customers_email_address,
                                                                                            c.customers_gender,
                                                                                            c.customers_dob,
                                                                                            c.customers_telephone,
                                                                                            o.customers_postcode,
                                                                                            o.customers_city,
                                                                                            o.customers_street_address
                                                                            FROM    orders o
                                                                            LEFT JOIN customers c
                                                                            ON              c.customers_id = o.customers_id
                                                                            WHERE   ( o.orders_status=3 OR o.orders_status=7 )
                                                                            AND     c.IsInNewsletter=0"
    );
           
            $loopInt = 1;
            //$output = 'geschlecht;anrede;vorname;nachname;email;birthday;telefon;plz;ort;street'. PHP_EOL;
            $output = 'geschlecht;anrede;vorname;nachname;email;geburtsdatum'. PHP_EOL;
           
            if ( xtc_db_num_rows($orders_query) > 0 )
            {
                    while($orders = xtc_db_fetch_array($orders_query))
                    {
                            // Anrede muss mit Join noch ausgelesen werden.
                            $output .= TranslateSex($orders['customers_gender']); // Anrede
                            $output .= ';';
                            $output .= TranslateGender($orders['customers_gender']); // Anrede
                            $output .= ';';
                            $output .= ReplaceTiltChars($orders['customers_firstname']); // Vorname
                            $output .= ';';
                            $output .= ReplaceTiltChars($orders['customers_lastname']); // Nachname
                            $output .= ';';
                            $output .= ReplaceTiltChars($orders['customers_email_address']); // Email Adresse
                            $output .= ';';
                            $output .= FormatBirthday($orders['customers_dob']); // Geburtsdatum
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_telephone']); // Telefon
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_postcode']); // PLZ
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_city']); // Ort
                            //$output .= ';';
                            //$output .= ReplaceTiltChars($orders['customers_street_address']); // Ort
                            $output .= PHP_EOL;
                           
                            $update = "UPDATE customers SET IsInNewsletter='' WHERE customers_id='".$orders['customers_id']."';";
                            xtc_db_query($update);
                            // Wenn Datensatz erfasst wurde, dann muss die Order auf Status IsInNewsletter=1 gesetzt werden.
                            $loopInt++;
                    }
                   
                    if ($loopInt > 1)
                    {
                            $handle = fopen($currentFileName, 'w');
                            fputs($handle, $output);
                            fclose($handle);
                    }
                   
            }
            //echo $loopInt;
            header('Location: orders.php');
     

    Gruss
    Hanspeter

    Scubi

    • Mitglied
    • Beiträge: 220
    Moin Hanpeter,

    vielen Dank für deine Hilfe. Das hat funktioniert.

    Gruß Scubi
    rechtstexte für onlineshop
    41 Antworten
    24314 Aufrufe
    09. April 2014, 15:23:40 von Darkcallen
    3 Antworten
    1612 Aufrufe
    02. Januar 2019, 17:22:23 von Tomcraft
    6 Antworten
    4135 Aufrufe
    30. Juli 2014, 18:38:46 von gruenbaer
    4 Antworten
    4374 Aufrufe
    14. Oktober 2012, 09:16:28 von karsta.de
               
    anything